﻿using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Frm;
using Ledict.ConditionExtract.Frm.NodeTree;
using Ledict.ConditionExtract.Model;
using Ledict.Utility.Helper;
using Ledict.Utility.Msg;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;

namespace Ledict.ConditionExtract
{
    /// <summary>
    /// 要素分析窗体
    /// </summary>
    public partial class ElementAnalyze : BaseForm
    {
        #region 构造单例
        //静态锁
        private static readonly object Lock = new object();
        public ElementAnalyze()
        {
            InitializeComponent();
        }

        static ElementAnalyze _default;
        public static ElementAnalyze Default
        {
            get
            {
                if (_default == null || _default.IsDisposed)
                {
                    lock (Lock)
                    {
                        if (_default == null || _default.IsDisposed)
                        {
                            _default = new ElementAnalyze();
                        }
                    }

                }
                return _default;
            }
        }
        #endregion

        TreeDataBLL trbll = new TreeDataBLL();
        RegexParse.RegexParse getregex = new RegexParse.RegexParse();
        ProcessDataSourceBLL datas = new ProcessDataSourceBLL();

        //法院数据表
        private static DataTable sysCourtTable = new DataTable();

        CaseCauseBLL caseCauseBll = new CaseCauseBLL();
        //案由数据表
        private static DataTable sysCaseCauseTable = new DataTable();

        SYS_CaseTypeBLL sysCaseTypeBll = new SYS_CaseTypeBLL();
        Sys_CourtBLL sysCourtBll = new Sys_CourtBLL();
        public static DataTable caseTreeNodeRode = new DataTable();
        private TreeNode clicknode;//点击节点树后，保存该节点
        private TreeNode editnode;//点击获得当前节点
        private TreeNode clicknodeNew;//点击节点树后，保存该节点
        private TreeNode editnodeNew;//点击获得当前节点

        RegInfoBLL regbll = new RegInfoBLL();
        private string regInfoCode = string.Empty;
        private static DataSourceCondition condi;
        LuceneSearch luceneSearch = new LuceneSearch();
        private DataTable dtNew = new DataTable();
        private DataTable dtNew1 = new DataTable();
        private readonly int pageNum = 10000;
        int page = 0;
        private string UpDataPath = string.Empty;
        private string DownData = string.Empty;
        Thread t;
        string indexPath = ConfigHelper.AppSettings("YaoSuFenXi");
        List<string> oldCases = new List<string>();
        int index = 0;

        SYS_ArgumentTextRelBLL sysArgumentBll = new SYS_ArgumentTextRelBLL();
        private DataTable dtsysArgument = new DataTable();
        CaseLogicPartInfoesBLL caseLogicbll = new CaseLogicPartInfoesBLL();
        static DataTable argumentdt = new DataTable();
        private List<TreeNode> NodeList = new List<TreeNode>();//节点树上显示出来的所有节点集合


        private void ElementAnalyze_Load(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvNew.AutoGenerateColumns = false;
            dgvNew.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvNew2.AutoGenerateColumns = false;
            dgvNew2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            GetData("t_Case_JudicialProcedure");
            GetData("t_Case_Property");
            GetData("t_Case_ParagraphType");
            //加载法院数据
            LoadSysCourtData();
            //加载案由数据
            LoadSysCaseCauseData();
            t_Case_ParagraphType.TreeView.CheckBoxes = t_Global_Court.TreeView.CheckBoxes = t_Case_Property.TreeView.CheckBoxes = t_Case_JudicialProcedure.TreeView.CheckBoxes = t_Case_HeadWords.TreeView.CheckBoxes = false;
            panelNew1.Visible = false;
            panelNew.Visible = false;
            panelOld.Visible = true;
            panelOld.Dock = DockStyle.Fill;
            cmbSource.SelectedIndex = 0;
        }

        /// <summary>
        /// 加载法院数据
        /// </summary>
        private void LoadSysCourtData()
        {
            sysCourtTable = sysCourtBll.GetSysCourtData();
            if (sysCourtTable.Rows.Count > 0)
            {
                if (sysCourtTable.Select("ParentID=''").Length > 0)
                {
                    DataTable sysCourtdt = sysCourtTable.Select(" ParentID='' ").CopyToDataTable<DataRow>();
                    foreach (DataRow dr in sysCourtdt.Rows)
                    {
                        TreeNode node = new TreeNode() { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        node.Nodes.Add(new TreeNode());
                        t_Global_Court.TreeView.Nodes.Add(node);
                    }
                    t_Global_Court.DropDownStyle = ComboBoxStyle.DropDown;
                    t_Global_Court.TreeView.AfterExpand += TreeView_AfterExpand; ;
                }
            }
        }

        /// <summary>
        /// 法院节点树展开事件 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            DataTable dt = new DataTable();
            if (sysCourtTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").Length > 0)
            {
                dt = sysCourtTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode node = new TreeNode { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCourtTable.Select(" ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            DataTable dtt = sysCourtTable.Select(" ParentID='" + node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }

        /// <summary>
        /// 赋值案由、逻辑段、法院、裁决程序、性质
        /// </summary>
        /// <param name="tname"></param>
        public void GetData(string tname)
        {

            DataTable dt = trbll.GetTreeHeadWords("", tname);// 第一层
            DataRow[] arrayDR = dt.Select();

            foreach (DataRow caseTreeNodeRode in arrayDR)
            {
                TreeNode node = new TreeNode();

                node.Text = caseTreeNodeRode["name"].ToString() + "(" + caseTreeNodeRode["id"].ToString() + ")";
                node.Tag = caseTreeNodeRode["id"];

                switch (tname)
                {
                    case "t_Case_HeadWords":
                        if (trbll.GetTreeHeadWords(node.Tag.ToString(), tname).Rows.Count > 0)//第二层
                        {
                            node.Nodes.Add(new TreeNode());
                        }
                        t_Case_HeadWords.TreeView.Nodes.Add(node);
                        break;
                    case "t_Case_JudicialProcedure":
                        t_Case_JudicialProcedure.TreeView.Nodes.Add(node);
                        break;
                    case "t_Case_Property":
                        t_Case_Property.TreeView.Nodes.Add(node);
                        break;
                    case "t_Global_Court":
                        if (trbll.GetTreeHeadWords(node.Tag.ToString(), tname).Rows.Count > 0)//第二层
                        {
                            node.Nodes.Add(new TreeNode());
                        }
                        t_Global_Court.TreeView.Nodes.Add(node);
                        break;
                    default:
                        t_Case_ParagraphType.TreeView.Nodes.Add(node);
                        break;

                }



            }
        }

        //public void GetTreeHeadWordsChild(TreeNode parentNode, string Tname)
        //{
        //    DataTable dt = trbll.GetTreeHeadWords(parentNode.Tag.ToString(), Tname);// 第一层
        //    DataRow[] arrayDR = dt.Select();

        //    foreach (DataRow caseTreeNodeRode in arrayDR)
        //    {
        //        TreeNode node = new TreeNode();

        //        node.Text = LdFormat.ObjectToString(caseTreeNodeRode["name"]) + "(" + caseTreeNodeRode["id"] + ")";
        //        node.Tag = caseTreeNodeRode["id"];
        //        if (trbll.GetTreeHeadWords(node.Tag.ToString(), Tname).Rows.Count > 0)//第二层
        //        {
        //            node.Nodes.Add(new TreeNode());
        //        }
        //        parentNode.Nodes.Add(node);

        //    }

        //}

        /// <summary>
        /// 加载案由数据
        /// </summary>
        private void LoadSysCaseCauseData()
        {
            sysCaseCauseTable = caseCauseBll.GetSysCaseCauseData();
            if (sysCaseCauseTable.Rows.Count > 0)
            {
                if (sysCaseCauseTable.Select("ID in('1000','1477','2329','2415','2449') ").Length > 0)
                {
                    DataTable sysCaseCausedt = sysCaseCauseTable.Select(" ID in('1000','1477','2329','2415','2449') ").CopyToDataTable<DataRow>();
                    foreach (DataRow dr in sysCaseCausedt.Rows)
                    {
                        TreeNode node = new TreeNode() { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        node.Nodes.Add(new TreeNode());
                        t_Case_HeadWords.TreeView.Nodes.Add(node);
                    }
                    t_Case_HeadWords.DropDownStyle = ComboBoxStyle.DropDown;
                    t_Case_HeadWords.TreeView.AfterExpand += TreeView_AfterExpandCaseCause;
                }
            }
        }

        /// <summary>
        /// 案由数据展开节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterExpandCaseCause(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            DataTable dt = new DataTable();
            if (sysCaseCauseTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").Length > 0)
            {
                dt = sysCaseCauseTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode node = new TreeNode { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCaseCauseTable.Select(" ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            DataTable dtt = sysCaseCauseTable.Select(" ParentID='" + node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }

        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartBtn_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = string.Empty;
            // GC.Collect();
            if (!string.IsNullOrEmpty(t_Case_HeadWords.Text.Trim()) && !string.IsNullOrEmpty(t_Case_ParagraphType.Text.Trim()) && !string.IsNullOrEmpty(t_Case_JudicialProcedure.Text.Trim()))
            {
                this.Cursor = Cursors.WaitCursor;

                if (t_Case_ParagraphType.Text.Trim() == "150")
                {
                    if (cmbSource.Text == "索引")
                    {
                        panelNew.Visible = true;
                        panelNew.Dock = DockStyle.Fill;
                        panelOld.Visible = false;
                        panelNew1.Visible = false;
                        LoadCaseCauseTree(t_Case_HeadWords.Text.Trim());
                        panelTitle.Visible = false;
                    }
                    else if (cmbSource.Text == "数据库")
                    {
                        NodeList = new List<TreeNode>();
                        panelTitle.Visible = true;
                        panelNew1.Visible = true;
                        panelNew1.Dock = DockStyle.Fill;
                        panelOld.Visible = false;
                        panelNew.Visible = false;
                        groupBox2.Visible = false;
                        argumentdt = sysArgumentBll.GetSysArgumentTextRelData();
                        lblNo.Text = sysArgumentBll.GetSysArgumentCount(t_Case_HeadWords.Text.Trim()).ToString();
                        LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                        dtsysArgument = sysArgumentBll.GetSysArgumentTextRelData(t_Case_HeadWords.Text.Trim());
                        if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                            {
                                dtsysArgument.Rows[i]["id"] = i + 1;
                            }
                            dataPager2.ChangePageNumber(1);
                        }
                        else
                        {
                            if (dtsysArgument != null)
                            {
                                dtsysArgument.Clear();
                            }
                            dataPager2.ChangePageNumber(1);
                            MessageBox.Show("没有获取到数据！");
                        }
                        this.Cursor = Cursors.Default;
                        dgvNew2.ClearSelection();
                        return;
                    }
                }
                else
                {
                    panelOld.Visible = true;
                    panelOld.Dock = DockStyle.Fill;
                    panelNew.Visible = false;
                    panelNew1.Visible = false;
                    panelTitle.Visible = false;
                }
                Application.DoEvents();
                #region MyRegion
                int MaxCount = 0;

                condi = new DataSourceCondition
                {
                    HeadwordId = t_Case_HeadWords.Text.Trim(),
                    JudicialProcedureId = t_Case_JudicialProcedure.Text.Trim(),
                    ParagraphType = t_Case_ParagraphType.Text.Trim(),
                    PropertyId = t_Case_Property.Text.Trim(),
                    Court = t_Global_Court.Text.Trim(),
                    SearchPerSize = pageNum //每次查询个数
                };
                MaxCount = luceneSearch.GetDataSourceCountNew(condi);
                if (MaxCount > 0)
                {
                    int perPage = pageNum; //每次从索引取5000条
                    page = (int)Math.Ceiling((double)MaxCount / perPage);
                    lblCount.Text = MaxCount.ToString();
                    lblShow.Text = "1-10000";
                    lblCurrent.Text = "1";
                    if (page == 1)
                    {
                        btnUp.Enabled = btnNext.Enabled = false;
                    }
                    else if (page > 1)
                    {
                        btnUp.Enabled = false;
                        btnNext.Enabled = true;
                    }
                    dtNew = luceneSearch.GetDataSourceNew(condi, Convert.ToInt32(lblCurrent.Text), perPage);

                    dtNew1 = dtNew = GetSelectData(dtNew);
                    if (t_Case_ParagraphType.Text.Trim() == "150")
                    {
                        if (checkBox1.Checked && !string.IsNullOrEmpty(regInfoCode) && txbKeyWords.Text.Trim().Contains("争议焦点"))
                        {
                            DataTable dtt = new DataTable();
                            string strOld = string.Empty;
                            string path1 = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim());
                            if (Directory.Exists(path1))
                            {
                                oldCases.Clear();
                                string[] strs = Directory.GetFiles(path1);
                                if (strs.Length > 0)
                                {
                                    foreach (string item in strs)
                                    {
                                        string path = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim()) + ".txt";
                                        if (item == path)
                                        {
                                            strOld = File.ReadAllText(path).Replace("\r\n", "");
                                            string[] str1s = strOld.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                            if (str1s.Length > 0)
                                            {
                                                oldCases = str1s.ToList();
                                            }
                                        }
                                    }
                                }
                            }
                            int i = 1;
                            DataTable dt = dtNew1.Clone();
                            DataTable dt1 = new DataTable();
                            dt.Columns.Add("CheckRow");
                            dt.Columns.Add("Par");
                            if (!string.IsNullOrEmpty(strOld))
                            {
                                if (dtNew1.Select(" CaseId not in (" + strOld + ")").Length > 0)
                                {
                                    dt1 = dtNew1.Select(" CaseId not in (" + strOld + ")").CopyToDataTable<DataRow>();
                                    dtt = dtNew1.Select(" CaseId  in (" + strOld + ")").CopyToDataTable<DataRow>();

                                }
                            }
                            else
                            {
                                dt1 = dtNew1;
                            }
                            foreach (DataRow item in dt1.Rows)
                            {
                                string ParText = item["ParagraphText"].ToString();
                                if (!string.IsNullOrEmpty(ParText))
                                {
                                    IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                    if (paralist.Count > 0)
                                    {
                                        foreach (string str in paralist)
                                        {
                                            DataRow dr = dt.NewRow();
                                            dr["Id"] = i;
                                            dr["CaseId"] = item["CaseId"].ToString();
                                            dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                            dr["ParagraphText"] = item["ParagraphText"].ToString();
                                            dr["Par"] = str.ToString().Trim();
                                            dr["PropertyId"] = item["PropertyId"].ToString();
                                            dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                            dr["CourtId"] = item["CourtId"].ToString();
                                            dr["ParagraphId"] = item["ParagraphId"].ToString();
                                            dr["CheckRow"] = false;
                                            dt.Rows.Add(dr);
                                            i++;
                                        }
                                    }
                                }
                            }
                            dgvNew.Columns["ParagraphText1"].Visible = false;
                            dgvNew.Columns["Par"].Visible = true;
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                int k = dt.Rows.Count + 1;

                                foreach (DataRow item in dtt.Rows)
                                {
                                    string ParText = item["ParagraphText"].ToString();
                                    if (!string.IsNullOrEmpty(ParText))
                                    {
                                        IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                        if (paralist.Count > 0)
                                        {
                                            foreach (string str in paralist)
                                            {
                                                DataRow dr = dt.NewRow();
                                                dr["Id"] = k;
                                                dr["CaseId"] = item["CaseId"].ToString();
                                                dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                                dr["ParagraphText"] = item["ParagraphText"].ToString();
                                                dr["Par"] = str.ToString().Trim();
                                                dr["PropertyId"] = item["PropertyId"].ToString();
                                                dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                                dr["CourtId"] = item["CourtId"].ToString();
                                                dr["ParagraphId"] = item["ParagraphId"].ToString();
                                                dr["CheckRow"] = true;
                                                dt.Rows.Add(dr);
                                                k++;
                                            }
                                        }
                                    }
                                }
                            }
                            dtNew1 = dt;
                            dataPager1.ChangePageNumber(1);
                        }
                        else
                        {
                            dgvNew.Columns["ParagraphText1"].Visible = true;
                            dgvNew.Columns["Par"].Visible = false;
                            for (int i = 0; i < dtNew1.Rows.Count; i++)
                            {
                                dtNew1.Rows[i]["Id"] = i + 1;
                            }
                            dataPager1.ChangePageNumber(1);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < dtNew.Rows.Count; i++)
                        {
                            dtNew.Rows[i]["Id"] = i + 1;
                        }
                        dataPagerMain.ChangePageNumber(1);
                    }
                    this.Cursor = Cursors.Default;
                    t = new Thread(Data);
                    t.Start();
                }
                else
                {
                    if (dtNew != null)
                    {
                        dtNew.Clear();
                    }
                    if (dtNew1 != null)
                    {
                        dtNew1.Clear();
                    }
                    this.Cursor = Cursors.Default;
                    dataPagerMain.ChangePageNumber(1);
                    dataPager1.ChangePageNumber(1);
                    MessageBox.Show("没有获取到数据！");
                }
                #endregion
                dataGridView1.ClearSelection();
                dgvNew.ClearSelection();
            }
            else
            {
                MsgBox.Warn(@"案由、逻辑段、裁决程序不可为空，请重新填写!");
                return;
            }

        }

        /// <summary>
        /// 获取节点树数据
        /// </summary>
        /// <param name="ccid"></param>
        private void LoadCaseCauseTree(string ccid)
        {
            tvNode.Nodes.Clear();
            caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(ccid);//父级ID的下级节点
            if (caseTreeNodeRode.Rows.Count == 0)
                return;
            if (caseTreeNodeRode.Select(" cc_id='" + ccid + "' ").Length > 0)
            {
                DataRow dr = caseTreeNodeRode.Select(" cc_id='" + ccid + "' ")[0];
                var node = new TreeNode();
                node.Text = dr["cc_name"].ToString();
                node.Tag = ccid;
                node.Name = dr["CC_NodeType"].ToString();
                if (caseTreeNodeRode.Select(" CC_ParentID='" + ccid + "' ").Length > 0)
                {
                    node.Nodes.Add(new TreeNode());
                }
                tvNode.Nodes.Add(node);
                tvNode.AfterExpand += TvNode_AfterExpand;
                tvNode.AfterSelect += TvNode_AfterSelect;
                tvNode.MouseDown += tvNode_MouseDown;
            }
        }

        /// <summary>
        /// 获取节点树数据
        /// </summary>
        /// <param name="ccid"></param>
        private void LoadCaseCauseTreeNew(string ccid)
        {
            tvNode1.Nodes.Clear();
            caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(ccid);//父级ID的下级节点
            if (caseTreeNodeRode.Rows.Count == 0)
                return;
            if (caseTreeNodeRode.Select(" cc_id='" + ccid + "' ").Length > 0)
            {
                DataRow dr = caseTreeNodeRode.Select(" cc_id='" + ccid + "' ")[0];
                var node = new TreeNode();
                node.Text = dr["cc_name"].ToString();
                node.Tag = ccid;
                node.Name = dr["CC_NodeType"].ToString();
               // node.ToolTipText = argumentdt.Select(" ATR_TypeID='" + ccid + "' ").Length.ToString();
                // e.Node.ToolTipText = e.Node.Text;
                if (caseTreeNodeRode.Select(" CC_ParentID='" + ccid + "' ").Length > 0)
                {
                    node.Nodes.Add(new TreeNode());
                }
                tvNode1.Nodes.Add(node);
                TreeNode node1 = null;

                foreach (var node2 in NodeList)//遍历现在界面上的所有节点
                {
                    if (node2.Tag.ToString() == node.Tag.ToString())
                    {
                        node1 = node2;
                        break;
                    }
                }
                if (node1 != null)
                {
                    NodeList.Remove(node1);
                    NodeList.Add(node);//list用来查询
                }
                else
                {
                    NodeList.Add(node);
                }
                tvNode1.AfterExpand += TvNode_AfterExpandNew;
                tvNode1.AfterSelect += TvNode_AfterSelectNew;
                tvNode1.MouseDown += tvNode_MouseDownNew;
                node.ExpandAll();
                node.Collapse(false);
            }
        }


        /// <summary>
        /// 右侧节点树鼠标按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvNode_MouseDownNew(object sender, MouseEventArgs e)
        {
            var clickPoint = new Point(e.X, e.Y);
            editnodeNew = tvNode1.GetNodeAt(clickPoint);
            if (editnodeNew != null)//判断你点的是不是一个节点
            {
                if (editnodeNew.FullPath.Contains("争议焦点要素"))
                {
                    if (editnodeNew.Level == 1)
                    {
                        添加同级节点ToolStripMenuItem.Visible = false;
                    }
                    else
                    {
                        添加同级节点ToolStripMenuItem.Visible = true;
                    }
                    SYS_CaseCause objCaseCause = caseCauseBll.GetCaseCauseByCCID(editnodeNew.Tag.ToString());
                    if (objCaseCause != null && objCaseCause.CC_NodeType == 12 && objCaseCause.CC_Name != "属性")
                    {
                        添加子节点ToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        添加子节点ToolStripMenuItem.Enabled = true;
                    }
                    editnodeNew.ContextMenuStrip = contextMenuStrip2;
                }
                //Typedt = casecausebLL.GetCaseCauseType();
                //NodeTypeList.DataSource = Typedt;
                //NodeTypeList.DisplayMember = "CC_NodeTypeName";
                //NodeTypeList.ValueMember = "CC_NodeType";
                tvNode1.SelectedNode = editnodeNew;//选中这个节点
            }
        }

        /// <summary>
        /// 右侧节点树展开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TvNode_AfterExpandNew(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            var pid = e.Node.Tag.ToString();// 父级ID
            if (caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' ").Length > 0)
            {
                DataRow[] drs;
                if (e.Node.Level == 0)
                {
                    drs = caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' and CC_Name in('争议焦点要素','诉请要素') ", " CC_SerialNumb");
                }
                else
                {
                    drs = caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' ", " CC_SerialNumb");
                }
                if (drs.Length > 0)
                {
                    foreach (var item in drs)
                    {
                        var node = new TreeNode();
                        node.Text = item["cc_name"].ToString();
                        node.Tag = item["cc_id"].ToString();
                        node.Name = item["CC_NodeType"].ToString();
                        if (e.Node.Level ==0)
                        {
                            DataTable dt1 = sysArgumentBll.GetSysArgumentTop(t_Case_HeadWords.Text.Split('|')[0].Trim());
                            if (dt1 != null && dt1.Rows.Count > 0)
                            {
                                string num = dt1.Rows[0]["atrNum"].ToString();
                                DataTable dt2 = dt1.Select(" atrNum='" + num + "' ").CopyToDataTable();
                                StringBuilder sb = new StringBuilder();
                                if (dt2 != null && dt2.Rows.Count > 0)
                                {
                                    foreach (DataRow it in dt2.Rows)
                                    {
                                        sb.Append(caseTreeNodeRode.Select(" cc_id='" + it[0].ToString().Trim() + "' ")[0][1] + "(" + num + ")" + "\r\n");
                                    }
                                    node.ToolTipText = sb.ToString();
                                }
                            }
                        }
                        else
                        {
                            if (node.Name == "16")
                            {
                                node.ToolTipText = argumentdt.Select(" ATR_TypeID='" + node.Tag + "' ").Length.ToString();
                            }
                        }
                        if (caseTreeNodeRode.Select(" CC_ParentID='" + node.Tag + "' ").Length > 0)
                        {
                            node.Nodes.Add(new TreeNode());
                        }
                        e.Node.Nodes.Add(node);
                        TreeNode node1 = null;

                        foreach (var node2 in NodeList)//遍历现在界面上的所有节点
                        {
                            if (node2.Tag.ToString() == node.Tag.ToString())
                            {
                                node1 = node2;
                                break;
                            }
                        }
                        if (node1 != null)
                        {
                            NodeList.Remove(node1);
                            NodeList.Add(node);//list用来查询
                        }
                        else
                        {
                            NodeList.Add(node);
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 右侧节点树选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TvNode_AfterSelectNew(object sender, TreeViewEventArgs e)
        {
            if (clicknodeNew != null && clicknodeNew.Text != e.Node.Text)
            {
                clicknodeNew.ForeColor = Color.Black;
            }
            if (e.Node != null)
            {
                clicknodeNew = e.Node;//保存节点
                clicknodeNew.ForeColor = Color.Red;
                //if (clicknodeNew.Level==0)
                //{
                //    dtsysArgument = sysArgumentBll.GetSysArgumentTextRelData(t_Case_HeadWords.Text.Trim());
                //    if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                //    {
                //        for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                //        {
                //            dtsysArgument.Rows[i]["id"] = i + 1;
                //        }
                //        dataPager2.ChangePageNumber(1);
                //    }
                //    else
                //    {
                //        if (dtsysArgument != null)
                //        {
                //            dtsysArgument.Clear();
                //        }
                //        dataPager2.ChangePageNumber(1);
                //        MessageBox.Show("没有获取到数据！");
                //    }
                //}
                //else if (clicknodeNew.Name.ToString()=="16"&& !string.IsNullOrEmpty(clicknodeNew.ToolTipText) && Convert.ToInt32(clicknodeNew.ToolTipText) > 0)
                //{
                //    if (argumentdt.Select(" ATR_TypeID='" + clicknodeNew.Tag.ToString() + "'").Length > 0)
                //    {
                //        dtsysArgument = argumentdt.Select(" ATR_TypeID='" + clicknodeNew.Tag.ToString() + "' ").CopyToDataTable();
                //        if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                //        {
                //            for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                //            {
                //                dtsysArgument.Rows[i]["ATR_ID"] = i + 1;
                //            }
                //            dataPager2.ChangePageNumber(1);
                //        }
                //        else
                //        {
                //            if (dtsysArgument != null)
                //            {
                //                dtsysArgument.Clear();
                //            }
                //            dataPager2.ChangePageNumber(1);
                //            MessageBox.Show("没有获取到数据！");
                //        }
                //    }
                //}
            }
        }

        /// <summary>
        /// 右侧节点树选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TvNode_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (clicknode != null && clicknode.Text != e.Node.Text)
            {
                clicknode.ForeColor = Color.Black;
            }
            if (e.Node != null)
            {
                clicknode = e.Node;//保存节点
                clicknode.ForeColor = Color.Red;
            }
        }

        /// <summary>
        /// 右侧节点树展开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TvNode_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            var pid = e.Node.Tag.ToString();// 父级ID
            if (caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' ").Length > 0)
            {
                DataRow[] drs;
                if (e.Node.Level == 0)
                {
                    drs = caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' and CC_Name in('争议焦点要素','诉请要素') ", " CC_SerialNumb");
                }
                else
                {
                    drs = caseTreeNodeRode.Select(" CC_ParentID='" + pid + "' ", " CC_SerialNumb");
                }
                if (drs.Length > 0)
                {
                    foreach (var item in drs)
                    {
                        var node = new TreeNode();
                        node.Text = item["cc_name"].ToString();
                        node.Tag = item["cc_id"].ToString();
                        node.Name = item["AllParentId"].ToString();
                        if (caseTreeNodeRode.Select(" CC_ParentID='" + node.Tag + "' ").Length > 0)
                        {
                            node.Nodes.Add(new TreeNode());
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }

        public static IList<T> PaginationDataSource<T>(IList<T> list, int pageIndex, int pageSize, int totals)
        {
            totals = 0;
            if (pageIndex < 0)
                throw new ArgumentException("pageIndex必须大于0");

            if (pageSize <= 0)
                throw new ArgumentException("pageSize必须大于0");


            totals = list.Count;
            int rowBegin = (pageIndex - 1) * pageSize >= totals ? 0 : (pageIndex - 1) * pageSize;
            int rowEnd = rowBegin + pageSize - 1 >= totals ? totals : rowBegin + pageSize;

            IList<T> result = new List<T>();

            for (int i = rowBegin; i < rowEnd; i++)
            {
                result.Add(list[i]);
            }
            return result;
        }

        /// <summary>
        /// 根据条件获取数据
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private DataTable GetSelectData(DataTable dt)
        {

            if (!string.IsNullOrEmpty(t_Global_Court.Text.Trim()) || !string.IsNullOrEmpty(t_Case_Property.Text.Trim()) || !string.IsNullOrEmpty(txbKeyWords.Text.Trim()))
            {
                DataTable data = dt.Copy();
                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(t_Global_Court.Text.Trim()) || !string.IsNullOrEmpty(t_Case_Property.Text.Trim()))
                {
                    sb.Append(" 1=1 ");
                    if (!string.IsNullOrEmpty(t_Global_Court.Text.Trim()))
                    {
                        sb.Append(" and CourtId='" + t_Global_Court.Text.Trim() + "' ");
                    }
                    if (!string.IsNullOrEmpty(t_Case_Property.Text.Trim()))
                    {
                        sb.Append(" and PropertyId='" + t_Case_Property.Text.Trim() + "' ");
                    }
                    //if (!string.IsNullOrEmpty(CaseIdStart.Text.Trim()) && !string.IsNullOrEmpty(CaseIdEnd.Text.Trim()))
                    //{
                    //    sb.Append(" and CaseId between'" + CaseIdStart.Text.Trim() + "' and '" + CaseIdEnd.Text.Trim() + "' ");
                    //}
                    if (data.Select(sb.ToString()).Length > 0)
                    {
                        data = data.Select(sb.ToString()).CopyToDataTable<DataRow>();
                    }
                    else
                    {
                        return new DataTable();
                    }
                }
                if (!string.IsNullOrEmpty(txbKeyWords.Text.Trim()))
                {
                    string[] keys = txbKeyWords.Text.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (keys.Length > 0)
                    {

                        for (int i = 0; i < keys.Length; i++)
                        {
                            sb.Clear();
                            string[] items = keys[i].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                            if (items.Length > 0)
                            {
                                sb.Append("  ParagraphText " + (items[0].ToString().Trim() == "包含" ? "like" : " not like ") + " '%" + items[1].ToString().Trim() + "%' ");
                            }
                            if (data.Select(sb.ToString()).Length > 0)
                            {
                                data = data.Select(sb.ToString()).CopyToDataTable<DataRow>();
                            }
                            else
                            {
                                return new DataTable();
                            }
                        }
                    }
                }
                //else
                //{
                //    if (data.Select(sb.ToString()).Length > 0)
                //    {
                //        data = data.Select(sb.ToString()).CopyToDataTable<DataRow>();
                //    }
                //    else
                //    {
                //        return new DataTable();
                //    }
                //}
                return data;
            }
            else
            {
                return dt;
            }
        }

        /// <summary>
        /// 分解数据表
        /// </summary>
        /// <param name="originalTab">需要分解的表</param>
        /// <param name="rowsNum">每个表包含的数据量</param>
        /// <returns></returns>
        public DataSet SplitDataTable(DataTable originalTab, int rowsNum)
        {
            //获取所需创建的表数量
            int tableNum = originalTab.Rows.Count / rowsNum;

            //获取数据余数
            int remainder = originalTab.Rows.Count % rowsNum;

            DataSet ds = new DataSet();

            //如果只需要创建1个表，直接将原始表存入DataSet
            if (tableNum == 0)
            {
                ds.Tables.Add(originalTab.Copy());
            }
            else
            {
                DataTable[] tableSlice = new DataTable[tableNum];

                //Save orginal columns into new table.
                for (int c = 0; c < tableNum; c++)
                {
                    tableSlice[c] = new DataTable();
                    foreach (DataColumn dc in originalTab.Columns)
                    {
                        tableSlice[c].Columns.Add(dc.ColumnName, dc.DataType);
                    }
                }
                //Import Rows
                for (int i = 0; i < tableNum; i++)
                {
                    // if the current table is not the last one
                    if (i != tableNum - 1)
                    {
                        for (int j = i * rowsNum; j < ((i + 1) * rowsNum); j++)
                        {
                            tableSlice[i].ImportRow(originalTab.Rows[j]);
                        }
                    }
                    else
                    {
                        for (int k = i * rowsNum; k < ((i + 1) * rowsNum + remainder); k++)
                        {
                            tableSlice[i].ImportRow(originalTab.Rows[k]);
                        }
                    }
                }

                //add all tables into a dataset
                foreach (DataTable dt in tableSlice)
                {
                    ds.Tables.Add(dt);
                }
            }
            return ds;
        }


        int startShowIndex;
        int endShowIndex;
        int Nowshowindex = 0;
        DataTable Alldt = new DataTable();

        private void dataPagerMain_PageNumberChanging(object sender, Controls.DataPagerPageIndexChangingEventArgs e)
        {
            //当前页
            var page = dataPagerMain._currentPageNumber;
            //每页显示条数
            var pageSize = e.MaximumRows;
            var startRowIndex = e.StartRowIndex;
            startShowIndex = startRowIndex + 1;
            var maximumRows = e.MaximumRows;
            var endRowIndex = e.StartRowIndex + e.MaximumRows;
            endShowIndex = endRowIndex;
            #region 查询条件

            IList<DataRow> dtRows = PaginationDataSource<DataRow>(dtNew.Select(), page, pageSize, dtNew.Rows.Count);
            #endregion

            if (dtRows.Count > 0)
            {
                e.TotalCount = dtNew.Rows.Count;

                //var newdt = Alldt.Clone();
                //DataRow[] dr = Alldt.Select("showindex>" + startRowIndex + " and showindex<=" + endRowIndex);
                //for (int i = 0; i < dr.Length; i++)
                //{
                //    newdt.ImportRow((DataRow)dr[i]);
                //}

                dataGridView1.DataSource = Alldt = dtRows.CopyToDataTable<DataRow>();
            }
            else
            {
                e.TotalCount = 0;
                dataGridView1.DataSource = new DataTable();
            }


        }

        /// <summary>
        /// 上一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToPre_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                richTextBox1.Text = "";
                Nowshowindex--;
                NextPro();
                DataRow[] dr = Alldt.Select("Id='" + Nowshowindex + "'");
                if (dr.Length > 0)
                {
                    string para = dr[0]["ParagraphText"].ToString();
                    IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
                    if (paralist.Count > 0)
                    {
                        foreach (var item in paralist)
                        {
                            if (item != "")
                            {
                                richTextBox1.Text += item + "\r\n";
                            }

                        }
                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[Nowshowindex - 1].Selected = true;
                    }
                    else
                    {
                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[Nowshowindex - 1].Selected = true;
                    }
                }
            }
        }

        /// <summary>
        /// 下一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToNext_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                richTextBox1.Text = "";
                Nowshowindex++;
                NextPro();
                DataRow[] dr = Alldt.Select("Id='" + Nowshowindex + "'");
                if (dr.Length > 0)
                {
                    string para = dr[0]["ParagraphText"].ToString();
                    IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
                    if (paralist.Count > 0)
                    {
                        foreach (var item in paralist)
                        {
                            if (item != "")
                            {
                                richTextBox1.Text += item + "\r\n";
                            }

                        }
                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[Nowshowindex - 1].Selected = true;
                    }
                    else
                    {
                        dataGridView1.ClearSelection();
                        dataGridView1.Rows[Nowshowindex - 1].Selected = true;
                    }
                }

            }
        }

        #region 定位
        /// <summary>
        /// 定位开始索引
        /// </summary>
        private int locationIndex = 0;
        /// <summary>
        /// 匹配关键字的集合
        /// </summary>
        private MatchCollection _matchCollection;
        /// <summary>
        /// 定位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LocateWord_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(SelectWord.Text.Trim())) return;

            richTextBox1.SelectionStart = 0;
            richTextBox1.SelectionLength = richTextBox1.Text.Length;
            richTextBox1.SelectionBackColor = Color.White;
            var r = new System.Text.RegularExpressions.Regex(SelectWord.Text.Trim()); //定义一个Regex对象实例
            var mc = r.Matches(richTextBox1.Text);
            //符合条件个数
            lblKeywordCount.Text = mc.Count.ToString();
            //当前第一条
            lblKeywordsCurrent.Text = 1.ToString();
            _matchCollection = mc;
            for (int i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
            {
                int start = mc[i].Index; //记录匹配字符的位置
                int length = (SelectWord.Text.Trim()).Length;
                richTextBox1.SelectionStart = start;
                richTextBox1.SelectionLength = length;
                richTextBox1.SelectionBackColor = Color.Red;
            }

            //定位到指定满足条件的第一个文字上  todo by zhangpeng
            var firstIndex = richTextBox1.Find(SelectWord.Text.Trim());
            //查询不到关键字则提示后直接退出
            if (firstIndex == -1)
            {
                MsgBox.Warn("查无此关键词");
                return;
            }


            richTextBox1.Focus();
            richTextBox1.SelectionStart = firstIndex;
            richTextBox1.ScrollToCaret();

        }

        /// <summary>
        /// 上一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblKeywordsPre_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(SelectWord.Text))
            {
                MsgBox.Warn("请输入关键词!");
                return;
            }
            if (_matchCollection == null || _matchCollection.Count == 0)
            {
                MsgBox.Warn("请先定位!");
                return;
            }
            if (0 <= (locationIndex - 1))
            {
                locationIndex--;
                int start = _matchCollection[locationIndex].Index;
                int length = (SelectWord.Text.Trim()).Length;
                richTextBox1.SelectionStart = start;
                richTextBox1.SelectionLength = length;
                richTextBox1.Focus();
                richTextBox1.ScrollToCaret();
                //当前第几条
                lblKeywordsCurrent.Text = (locationIndex + 1).ToString();

            }
            else
            {
                MsgBox.Warn("已经是第一个");
                return;
            }
        }

        /// <summary>
        /// 下一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblNext_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(SelectWord.Text))
            {
                MsgBox.Warn("请输入关键词!");
                return;
            }
            if (_matchCollection == null || _matchCollection.Count == 0)
            {
                MsgBox.Warn("请先定位!");
                return;
            }

            if (_matchCollection.Count > (locationIndex + 1))
            {
                locationIndex++;
                int start = _matchCollection[locationIndex].Index;
                int length = (SelectWord.Text.Trim()).Length;
                richTextBox1.SelectionStart = start;
                richTextBox1.SelectionLength = length;
                richTextBox1.Focus();
                richTextBox1.ScrollToCaret();
                //当前第几条
                lblKeywordsCurrent.Text = (locationIndex + 1).ToString();
            }
            else
            {
                MsgBox.Warn("已经是最后一个");
                return;
            }
        }

        #endregion

        /// <summary>
        /// 数据区选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            richTextBox1.Text = "";
            string para = dataGridView1.Rows[e.RowIndex].Cells["ParagraphText"].Value.ToString();

            Nowshowindex = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value.ToString());
            NextPro();
            IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
            if (paralist.Count > 0)
            {
                foreach (var item in paralist)
                {
                    if (item != "")
                    {
                        richTextBox1.Text += item + "\r\n";
                    }
                }
            }
        }

        public void NextPro()
        {
            if (dataPagerMain._currentPageNumber == 0)
            {
                if (Nowshowindex <= 0)
                {
                    ToPre.Enabled = false;
                }
                else
                {
                    ToPre.Enabled = true;
                }
            }
            else
            {
                if (Nowshowindex <= startShowIndex)
                {
                    ToPre.Enabled = false;
                }
                else
                {
                    ToPre.Enabled = true;
                }
                if (Nowshowindex >= endShowIndex)
                {
                    ToNext.Enabled = false;
                }
                else
                {
                    ToNext.Enabled = true;
                }
            }

        }

        /// <summary>
        /// 添加关键词
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddCondition_Click(object sender, EventArgs e)
        {
            FrmCondition f = new FrmCondition(txbKeyWords.Text.Trim());
            if (f.ShowDialog() == DialogResult.Yes)
            {
                txbKeyWords.Text = f.Condition;
            }
        }

        /// <summary>
        /// datatable转json
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public string DataTableJson(DataTable dt)
        {
            string jsonString = string.Empty;
            jsonString = JsonConvert.SerializeObject(dt);
            return jsonString;
        }


        #region Json 字符串 转换为 DataTable数据集合
        /// <summary>
        /// Json 字符串 转换为 DataTable数据集合
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public DataTable ToDataTable(string json)
        {
            DataTable dataTable = new DataTable();  //实例化
            DataTable result;
            try
            {
                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
                ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
                if (arrayList.Count > 0)
                {
                    foreach (Dictionary<string, object> dictionary in arrayList)
                    {
                        if (dictionary.Keys.Count == 0)
                        {
                            result = dataTable;
                            return result;
                        }
                        if (dataTable.Columns.Count == 0)
                        {
                            foreach (string current in dictionary.Keys)
                            {
                                dataTable.Columns.Add(current, dictionary[current].GetType());
                            }
                        }
                        DataRow dataRow = dataTable.NewRow();
                        foreach (string current in dictionary.Keys)
                        {
                            dataRow[current] = dictionary[current];
                        }

                        dataTable.Rows.Add(dataRow); //循环添加行到DataTable中
                    }
                }
            }
            catch
            {
            }
            result = dataTable;
            return result;
        }
        #endregion


        /// <summary>
        /// 加载数据
        /// </summary>
        private void Data()
        {
            if (btnUp.Enabled == true && Convert.ToInt32(lblCurrent.Text) - 1 >= 1)
            {
                DataTable dt1 = luceneSearch.GetDataSourceNew(condi, Convert.ToInt32(lblCurrent.Text) - 1, pageNum);
                StreamWriter sw = new StreamWriter(System.Environment.CurrentDirectory + "\\Updata.txt", false, System.Text.Encoding.UTF8);
                string str = DataTableJson(dt1);
                sw.WriteLine(str);
                sw.Flush();
                sw.Close();
                UpDataPath = System.Environment.CurrentDirectory + "\\Updata.txt";
            }
            if (btnNext.Enabled == true && Convert.ToInt32(lblCurrent.Text) + 1 <= Convert.ToInt32(lblCount.Text))
            {
                DataTable dt2 = luceneSearch.GetDataSourceNew(condi, Convert.ToInt32(lblCurrent.Text) + 1, pageNum);
                StreamWriter sw = new StreamWriter(System.Environment.CurrentDirectory + "\\Downdata.txt", false, System.Text.Encoding.UTF8);
                string str = DataTableJson(dt2);
                sw.WriteLine(str);
                sw.Flush();
                sw.Close();
                DownData = System.Environment.CurrentDirectory + "\\Downdata.txt";
            }
        }

        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (btnNext.Enabled == true && Convert.ToInt32(lblCurrent.Text) + 1 <= Convert.ToInt32(page))
            {
                if (t.ThreadState != ThreadState.Stopped)
                {
                    MessageBox.Show("请等待数据缓冲完整后再试！");
                    return;
                }
                if (!string.IsNullOrEmpty(DownData) && File.Exists(DownData))
                {
                    StreamReader st = new StreamReader(DownData, System.Text.Encoding.UTF8);
                    string str1 = st.ReadToEnd();
                    dtNew = ToDataTable(str1);
                    st.Dispose();
                    st.Close();
                }
                dtNew = GetSelectData(dtNew);


                if (t_Case_ParagraphType.Text.Trim() == "150")
                {
                    if (checkBox1.Checked && !string.IsNullOrEmpty(regInfoCode) && txbKeyWords.Text.Trim().Contains("争议焦点"))
                    {
                        DataTable dtt = new DataTable();
                        string strOld = string.Empty;
                        string path1 = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim());
                        if (Directory.Exists(path1))
                        {
                            oldCases.Clear();
                            string[] strs = Directory.GetFiles(path1);
                            if (strs.Length > 0)
                            {
                                foreach (string item in strs)
                                {
                                    string path = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim()) + ".txt";
                                    if (item == path)
                                    {
                                        strOld = File.ReadAllText(path);
                                        string[] str1s = strOld.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        if (str1s.Length > 0)
                                        {
                                            oldCases = str1s.ToList();
                                        }
                                    }
                                }
                            }
                        }
                        int i = 1;
                        DataTable dt = dtNew1.Clone();
                        //dt.Columns.Add("CheckRow");
                        //dt.Columns.Add("Par");
                        if (!string.IsNullOrEmpty(strOld))
                        {
                            if (dtNew1.Select(" CaseId not in (" + strOld + ")").Length > 0)
                            {
                                dtNew1 = dtNew1.Select(" CaseId not in (" + strOld + ")").CopyToDataTable<DataRow>();
                                if (dtNew1.Select(" CaseId  in (" + strOld + ")").Length > 0)
                                {
                                    dtt = dtNew1.Select(" CaseId  in (" + strOld + ")").CopyToDataTable<DataRow>();
                                }
                            }
                        }
                        foreach (DataRow item in dtNew1.Rows)
                        {
                            string ParText = item["ParagraphText"].ToString();
                            if (!string.IsNullOrEmpty(ParText))
                            {
                                IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                if (paralist.Count > 0)
                                {
                                    foreach (string str in paralist)
                                    {
                                        DataRow dr = dt.NewRow();
                                        dr["Id"] = i;
                                        dr["CaseId"] = item["CaseId"].ToString();
                                        dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                        dr["ParagraphText"] = item["ParagraphText"].ToString();
                                        dr["Par"] = str.ToString().Trim();
                                        dr["PropertyId"] = item["PropertyId"].ToString();
                                        dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                        dr["CourtId"] = item["CourtId"].ToString();
                                        dr["ParagraphId"] = item["ParagraphId"].ToString();
                                        dr["CheckRow"] = false;
                                        dt.Rows.Add(dr);
                                        i++;
                                    }
                                }
                            }
                        }
                        dgvNew.Columns["ParagraphText1"].Visible = false;
                        dgvNew.Columns["Par"].Visible = true;
                        if (dtt != null && dtt.Rows.Count > 0)
                        {
                            int k = dt.Rows.Count + 1;

                            foreach (DataRow item in dtt.Rows)
                            {
                                string ParText = item["ParagraphText"].ToString();
                                if (!string.IsNullOrEmpty(ParText))
                                {
                                    IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                    if (paralist.Count > 0)
                                    {
                                        foreach (string str in paralist)
                                        {
                                            DataRow dr = dt.NewRow();
                                            dr["Id"] = k;
                                            dr["CaseId"] = item["CaseId"].ToString();
                                            dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                            dr["ParagraphText"] = item["ParagraphText"].ToString();
                                            dr["Par"] = str.ToString().Trim();
                                            dr["PropertyId"] = item["PropertyId"].ToString();
                                            dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                            dr["CourtId"] = item["CourtId"].ToString();
                                            dr["ParagraphId"] = item["ParagraphId"].ToString();
                                            dr["CheckRow"] = true;
                                            dt.Rows.Add(dr);
                                            k++;
                                        }
                                    }
                                }
                            }
                        }
                        dtNew1 = dt;
                        dataPager1.ChangePageNumber(1);
                    }
                    else
                    {
                        dgvNew.Columns["ParagraphText1"].Visible = true;
                        dgvNew.Columns["Par"].Visible = false;
                        for (int i = 0; i < dtNew1.Rows.Count; i++)
                        {
                            dtNew1.Rows[i]["Id"] = i + 1;
                        }
                        dataPager1.ChangePageNumber(1);
                    }
                }
                else
                {
                    for (int i = 0; i < dtNew.Rows.Count; i++)
                    {
                        dtNew.Rows[i]["Id"] = i + 1;
                    }
                    dataPagerMain.ChangePageNumber(1);
                }
                lblShow.Text = Convert.ToInt32(lblCurrent.Text) * pageNum + 1 + "-" + ((Convert.ToInt32(lblCurrent.Text) + 1) * pageNum > Convert.ToInt32(lblCount.Text) ? Convert.ToInt32(lblCount.Text) : (Convert.ToInt32(lblCurrent.Text) + 1) * pageNum);
                lblCurrent.Text = (Convert.ToInt32(lblCurrent.Text) + 1).ToString();
                if (lblCurrent.Text == lblCount.Text)
                {
                    btnNext.Enabled = false;
                }
                if (Convert.ToInt32(lblCurrent.Text) - 1 >= 1)
                {
                    btnUp.Enabled = true;
                }
                if (t.ThreadState == ThreadState.Stopped)
                {
                    t = new Thread(Data);
                    t.Start();
                }
            }
        }

        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUp_Click(object sender, EventArgs e)
        {
            if (btnUp.Enabled == true && Convert.ToInt32(lblCurrent.Text) - 1 >= 1)
            {
                if (t.ThreadState != ThreadState.Stopped)
                {
                    MessageBox.Show("请等待数据缓冲完整后再试！");
                    return;
                }
                if (!string.IsNullOrEmpty(UpDataPath) && File.Exists(UpDataPath))
                {
                    StreamReader st = new StreamReader(UpDataPath, System.Text.Encoding.UTF8);
                    string str1 = st.ReadToEnd();
                    dtNew = ToDataTable(str1);
                    st.Dispose();
                    st.Close();
                }
                dtNew = GetSelectData(dtNew);
                if (t_Case_ParagraphType.Text.Trim() == "150")
                {
                    if (checkBox1.Checked && !string.IsNullOrEmpty(regInfoCode) && txbKeyWords.Text.Trim().Contains("争议焦点"))
                    {
                        DataTable dtt = new DataTable();
                        string strOld = string.Empty;
                        string path1 = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim());
                        if (Directory.Exists(path1))
                        {
                            oldCases.Clear();
                            string[] strs = Directory.GetFiles(path1);
                            if (strs.Length > 0)
                            {
                                foreach (string item in strs)
                                {
                                    string path = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim()) + ".txt";
                                    if (item == path)
                                    {
                                        strOld = File.ReadAllText(path);
                                        string[] str1s = strOld.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        if (str1s.Length > 0)
                                        {
                                            oldCases = str1s.ToList();
                                        }
                                    }
                                }
                            }
                        }
                        int i = 1;
                        DataTable dt = dtNew1.Clone();
                        //dt.Columns.Add("CheckRow");
                        //dt.Columns.Add("Par");
                        if (!string.IsNullOrEmpty(strOld))
                        {
                            if (dtNew1.Select(" CaseId not in (" + strOld + ")").Length > 0)
                            {
                                dtNew1 = dtNew1.Select(" CaseId not in (" + strOld + ")").CopyToDataTable<DataRow>();
                                if (dtNew1.Select(" CaseId  in (" + strOld + ")").Length > 0)
                                {
                                    dtt = dtNew1.Select(" CaseId  in (" + strOld + ")").CopyToDataTable<DataRow>();
                                }
                            }
                        }
                        foreach (DataRow item in dtNew1.Rows)
                        {
                            string ParText = item["ParagraphText"].ToString();
                            if (!string.IsNullOrEmpty(ParText))
                            {
                                IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                if (paralist.Count > 0)
                                {
                                    foreach (string str in paralist)
                                    {
                                        DataRow dr = dt.NewRow();
                                        dr["Id"] = i;
                                        dr["CaseId"] = item["CaseId"].ToString();
                                        dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                        dr["ParagraphText"] = item["ParagraphText"].ToString();
                                        dr["Par"] = str.ToString().Trim();
                                        dr["PropertyId"] = item["PropertyId"].ToString();
                                        dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                        dr["CourtId"] = item["CourtId"].ToString();
                                        dr["ParagraphId"] = item["ParagraphId"].ToString();
                                        dr["CheckRow"] = false;
                                        dt.Rows.Add(dr);
                                        i++;
                                    }
                                }
                            }
                        }
                        dgvNew.Columns["ParagraphText1"].Visible = false;
                        dgvNew.Columns["Par"].Visible = true;
                        if (dtt != null && dtt.Rows.Count > 0)
                        {
                            int k = dt.Rows.Count + 1;

                            foreach (DataRow item in dtt.Rows)
                            {
                                string ParText = item["ParagraphText"].ToString();
                                if (!string.IsNullOrEmpty(ParText))
                                {
                                    IList<string> paralist = getregex.GetParseList(regInfoCode, ParText);
                                    if (paralist.Count > 0)
                                    {
                                        foreach (string str in paralist)
                                        {
                                            DataRow dr = dt.NewRow();
                                            dr["Id"] = k;
                                            dr["CaseId"] = item["CaseId"].ToString();
                                            dr["ParagraphTypeId"] = item["ParagraphTypeId"].ToString();
                                            dr["ParagraphText"] = item["ParagraphText"].ToString();
                                            dr["Par"] = str.ToString().Trim();
                                            dr["PropertyId"] = item["PropertyId"].ToString();
                                            dr["JudicialProcedureId"] = item["JudicialProcedureId"].ToString();
                                            dr["CourtId"] = item["CourtId"].ToString();
                                            dr["ParagraphId"] = item["ParagraphId"].ToString();
                                            dr["CheckRow"] = true;
                                            dt.Rows.Add(dr);
                                            k++;
                                        }
                                    }
                                }
                            }
                        }
                        dtNew1 = dt;
                        dataPager1.ChangePageNumber(1);
                    }
                    else
                    {
                        dgvNew.Columns["ParagraphText1"].Visible = true;
                        dgvNew.Columns["Par"].Visible = false;
                        for (int i = 0; i < dtNew1.Rows.Count; i++)
                        {
                            dtNew1.Rows[i]["Id"] = i + 1;
                        }
                        dataPager1.ChangePageNumber(1);
                    }
                }
                else
                {
                    for (int i = 0; i < dtNew.Rows.Count; i++)
                    {
                        dtNew.Rows[i]["Id"] = i + 1;
                    }
                    dataPagerMain.ChangePageNumber(1);
                }
                lblCurrent.Text = (Convert.ToInt32(lblCurrent.Text) - 1).ToString();
                lblShow.Text = (Convert.ToInt32(lblCurrent.Text) - 1) * pageNum + 1 + "-" + Convert.ToInt32(lblCurrent.Text) * pageNum;
                if (lblCurrent.Text == "1")
                {
                    lblShow.Text = "1-10000";
                    btnUp.Enabled = false;
                }
                if (Convert.ToInt32(lblCurrent.Text) + 1 <= Convert.ToInt32(lblCount.Text))
                {
                    btnNext.Enabled = true;
                }
                if (t.ThreadState == ThreadState.Stopped)
                {
                    t = new Thread(Data);
                    t.Start();
                }
            }

        }


        /// <summary>
        /// 案由文本框改变项事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void t_Case_HeadWords_TextUpdate(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(t_Case_HeadWords.Text))
            {
                if (sysCaseCauseTable.Select("Name like '%" + t_Case_HeadWords.Text + "%'").Length > 0)
                {
                    DataTable dt3 = sysCaseCauseTable.Select("Name like '%" + t_Case_HeadWords.Text + "%'").CopyToDataTable<DataRow>();
                    t_Case_HeadWords.TreeView.Nodes.Clear();
                    if (dt3 != null && dt3.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt3.Rows.Count; i++)
                        {
                            TreeNode node = new TreeNode();
                            node.Text = dt3.Rows[i]["Name"].ToString();
                            node.Tag = dt3.Rows[i]["ID"].ToString();
                            if (sysCourtTable.Select("ParentID='" + node.Tag + "'").Length > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                            t_Case_HeadWords.TreeView.Nodes.Add(node);
                        }
                    }
                }
                else
                {
                    t_Case_HeadWords.TreeView.Nodes.Clear();
                }
            }
            else
            {
                t_Case_HeadWords.TreeView.Nodes.Clear();
                LoadSysCaseCauseData();
            }
        }

        /// <summary>
        /// 法院文本改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void t_Global_Court_TextUpdate(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(t_Global_Court.Text))
            {
                if (sysCourtTable.Select("Name like '%" + t_Global_Court.Text + "%'").Length > 0)
                {
                    DataTable dt3 = sysCourtTable.Select("Name like '%" + t_Global_Court.Text + "%'").CopyToDataTable<DataRow>();
                    t_Global_Court.TreeView.Nodes.Clear();
                    if (dt3 != null && dt3.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt3.Rows.Count; i++)
                        {
                            TreeNode node = new TreeNode();
                            node.Text = dt3.Rows[i]["Name"].ToString();
                            node.Tag = dt3.Rows[i]["ID"].ToString();
                            if (sysCourtTable.Select("ParentID='" + node.Tag + "'").Length > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                            t_Global_Court.TreeView.Nodes.Add(node);
                        }
                    }
                }
                else
                {
                    t_Global_Court.TreeView.Nodes.Clear();
                }
            }
            else
            {
                t_Global_Court.TreeView.Nodes.Clear();
                LoadSysCourtData();
            }
        }

        /// <summary>
        /// 案由文本改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void t_Case_HeadWords_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(t_Case_HeadWords.Text) && sysCaseCauseTable.Select(" ID =" + t_Case_HeadWords.Text.Trim()).Length > 0)
            {
                string ccid = t_Case_HeadWords.Text.Trim();
                sysCaseCauseTable = caseCauseBll.GetSysCaseCauseData();
                if (sysCaseCauseTable.Rows.Count > 0)
                {
                    if (sysCaseCauseTable.Select("ID in('1000','1477','2329','2415','2449') ").Length > 0)
                    {
                        DataTable sysCaseCausedt = sysCaseCauseTable.Select(" ID in('1000','1477','2329','2415','2449') ").CopyToDataTable<DataRow>();
                        foreach (DataRow dr in sysCaseCausedt.Rows)
                        {
                            TreeNode node = new TreeNode() { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                            node.Nodes.Add(new TreeNode());
                            t_Case_HeadWords.TreeView.Nodes.Add(node);
                        }
                        t_Case_HeadWords.DropDownStyle = ComboBoxStyle.DropDown;
                        t_Case_HeadWords.TreeView.AfterExpand += TreeView_AfterExpandCaseCause;
                    }
                }
            }
        }

        #region 节点树事件

        /// <summary>
        /// 右侧节点树鼠标按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvNode_MouseDown(object sender, MouseEventArgs e)
        {
            var clickPoint = new Point(e.X, e.Y);
            editnode = tvNode.GetNodeAt(clickPoint);
            if (editnode != null)//判断你点的是不是一个节点
            {
                if (editnode.FullPath.Contains("争议焦点要素"))
                {
                    if (editnode.Level == 1)
                    {
                        添加同级节点ToolStripMenuItem.Visible = false;
                    }
                    else
                    {
                        添加同级节点ToolStripMenuItem.Visible = true;
                    }
                    SYS_CaseCause objCaseCause = caseCauseBll.GetCaseCauseByCCID(editnode.Tag.ToString());
                    if (objCaseCause != null && objCaseCause.CC_NodeType == 12 && objCaseCause.CC_Name != "属性")
                    {
                        添加子节点ToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        添加子节点ToolStripMenuItem.Enabled = true;
                    }
                    editnode.ContextMenuStrip = contextMenuStrip1;
                }
                //Typedt = casecausebLL.GetCaseCauseType();
                //NodeTypeList.DataSource = Typedt;
                //NodeTypeList.DisplayMember = "CC_NodeTypeName";
                //NodeTypeList.ValueMember = "CC_NodeType";
                tvNode.SelectedNode = editnode;//选中这个节点
            }
        }

        /// <summary>
        /// 全部展开事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 全部展开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            clicknode?.ExpandAll();
        }

        /// <summary>
        /// 添加同级节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 添加同级节点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddCaseNode addNode = new AddCaseNode("添加同级节点", clicknode.Parent.Text, clicknode.Parent.FullPath, clicknode.Parent.Tag.ToString());
            var dialogResult = addNode.ShowDialog();
            if (dialogResult == DialogResult.Yes)
            {
                caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                clicknode.Parent.Collapse();
                clicknode.Parent.Expand();
            }
        }

        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 添加子节点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddCaseNode addNode = new AddCaseNode("添加子节点", clicknode.Text, clicknode.FullPath, clicknode.Tag.ToString());
            var dialogResult = addNode.ShowDialog();
            if (dialogResult == DialogResult.Yes)
            {
                caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节点
                clicknode.Collapse();
                clicknode.Nodes.Clear();
                if (caseTreeNodeRode.Select(" CC_ParentID='" + clicknode.Tag.ToString() + "' ").Length > 0)
                {
                    DataRow[] drs;
                    drs = caseTreeNodeRode.Select(" CC_ParentID='" + clicknode.Tag.ToString() + "' ", " CC_SerialNumb");

                    if (drs.Length > 0)
                    {
                        foreach (var item in drs)
                        {
                            var node = new TreeNode();
                            node.Text = item["cc_name"].ToString();
                            node.Tag = item["cc_id"].ToString();
                            node.Name = item["AllParentId"].ToString();
                            if (caseTreeNodeRode.Select(" CC_ParentID='" + node.Tag + "' ").Length > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                            clicknode.Nodes.Add(node);
                        }
                    }
                }
                clicknode.Expand();
            }
        }

        /// <summary>
        /// 删除子节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认要删除节点" + clicknode.Text + "及其子节点吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    if (caseCauseBll.DeleteSYS_CaseCause(clicknode.Tag.ToString(), clicknode.Text, Gvar.uo.m_displayName))
                    {
                        MessageBox.Show("删除成功!");
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节点
                        clicknode.Parent.Nodes.Remove(clicknode);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("删除失败!" + ex.Message);
                }
            }
        }
        #endregion

        /// <summary>
        /// 运行规则后选择规则事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                ElementRules f = new ElementRules();
                if (f.ShowDialog() == DialogResult.Yes)
                {
                    regInfoCode = f.InfoCode;
                }
            }
            else
            {
                regInfoCode = string.Empty;
            }
        }

        /// <summary>
        /// 提交按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTiJiao_Click(object sender, EventArgs e)
        {
            List<string> caseID = new List<string>();
            StringBuilder sb = new StringBuilder();
            int num = 0;
            for (var i = 0; i <= dgvNew.Rows.Count - 1; i++)
            {
                var check = (DataGridViewCheckBoxCell)dgvNew.Rows[i].Cells["CheckRow"];
                if (check.Value != DBNull.Value && Convert.ToBoolean(check.Value))
                {
                    if (!caseID.Contains(dgvNew.Rows[i].Cells["CaseId1"].Value.ToString()))
                    {
                        caseID.Add(dgvNew.Rows[i].Cells["CaseId1"].Value.ToString());
                    }
                    num++;
                }
            }
            if (num == 0)
            {
                MsgBox.Warn("请勾选需要标记的数据后再试");
                return;
            }
            else if (num > 0 && caseID.Count > 0)
            {
                lbelCount.Text = num.ToString();
                foreach (var item in caseID)
                {
                    if (!oldCases.Contains("'" + item + "'"))
                    {
                        sb.Append("'" + item + "',");
                    }
                }
                if (!string.IsNullOrEmpty(sb.ToString()) && checkBox1.Checked)
                {
                    string result = sb.ToString().Remove(sb.ToString().Length - 1, 1).Trim();
                    if (result.Length > 0)
                    {
                        //保存到12共享路径
                        if (!string.IsNullOrEmpty(t_Case_HeadWords.Text.Trim()) && !string.IsNullOrEmpty(t_Case_ParagraphType.Text.Trim()) && !string.IsNullOrEmpty(t_Case_JudicialProcedure.Text.Trim()))
                        {
                            if (Directory.Exists(indexPath))
                            {
                                string[] dirs = Directory.GetDirectories(indexPath);
                                if (dirs.Length > 0)
                                {
                                    bool res = false;
                                    foreach (string item in dirs)
                                    {
                                        if (Path.GetFileNameWithoutExtension(item) == t_Case_HeadWords.Text.Trim())
                                        {
                                            string path = Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim()) + ".txt";
                                            if (File.Exists(path))
                                            {
                                                StreamWriter sr = new StreamWriter(path, true);
                                                sr.WriteLine("," + result);
                                                sr.Close();
                                            }
                                            else
                                            {
                                                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                                                StreamWriter sw = new StreamWriter(fs);
                                                sw.WriteLine(result);
                                                sw.Close();
                                                fs.Close();
                                            }
                                            res = true;
                                        }
                                    }
                                    if (!res)
                                    {
                                        Directory.CreateDirectory(Path.Combine(indexPath, t_Case_HeadWords.Text.Trim()));
                                        FileStream fs = new FileStream(Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim()) + ".txt", FileMode.Create, FileAccess.Write);
                                        StreamWriter sw = new StreamWriter(fs);
                                        sw.WriteLine(result);
                                        sw.Close();
                                        fs.Close();
                                    }
                                }
                                else
                                {
                                    Directory.CreateDirectory(Path.Combine(indexPath, t_Case_HeadWords.Text.Trim()));
                                    FileStream fs = new FileStream(Path.Combine(indexPath, t_Case_HeadWords.Text.Trim(), t_Case_JudicialProcedure.Text.Trim() + "," + t_Case_ParagraphType.Text.Trim() + ".txt"), FileMode.Create, FileAccess.Write);
                                    StreamWriter sw = new StreamWriter(fs);
                                    sw.WriteLine(result);
                                    sw.Close();
                                    fs.Close();
                                }
                            }
                        }
                    }
                }
            }
        }

        int startShowIndex1;
        int endShowIndex1;
        int Nowshowindex1 = 0;
        DataTable Alldt1 = new DataTable();

        /// <summary>
        /// 新分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataPager1_PageNumberChanging(object sender, Controls.DataPagerPageIndexChangingEventArgs e)
        {
            //当前页
            var page = dataPager1._currentPageNumber;
            //每页显示条数
            var pageSize = e.MaximumRows;
            var startRowIndex = e.StartRowIndex;
            startShowIndex1 = startRowIndex + 1;
            var maximumRows = e.MaximumRows;
            var endRowIndex = e.StartRowIndex + e.MaximumRows;
            endShowIndex1 = endRowIndex;
            #region 查询条件
            lbelCount.Text = "";
            IList<DataRow> dtRows = PaginationDataSource<DataRow>(dtNew1.Select(), page, pageSize, dtNew1.Rows.Count);
            #endregion

            if (dtRows.Count > 0)
            {
                e.TotalCount = dtNew1.Rows.Count;
                dgvNew.DataSource = Alldt1 = dtRows.CopyToDataTable<DataRow>();
            }
            else
            {
                e.TotalCount = 0;
                dgvNew.DataSource = new DataTable();
            }
            dgvNew.ClearSelection();
            rtbNew.Text = "";
        }

        /// <summary>
        /// 新上一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblToPre_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (dgvNew.SelectedRows.Count > 0)
            {
                rtbNew.Text = "";
                Nowshowindex1--;
                NextPro1();
                DataRow[] dr = Alldt1.Select("Id='" + Nowshowindex1 + "'");
                if (dr.Length > 0)
                {
                    string para = dr[0]["ParagraphText"].ToString();
                    IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
                    if (paralist.Count > 0)
                    {
                        foreach (var item in paralist)
                        {
                            if (item != "")
                            {
                                rtbNew.Text += item + "\r\n";
                            }
                        }
                        string par = dr[0]["Par"].ToString();
                        //定位
                        if (!string.IsNullOrEmpty(par))
                        {
                            PositionExtractValue(par.Remove(par.Length - 1, 1));
                        }
                        dgvNew.ClearSelection();
                        if (Nowshowindex1 <= Properties.Settings.Default.PageSize)
                        {
                            dgvNew.Rows[Nowshowindex1 - 1].Selected = true;
                        }
                        else
                        {
                            int row = Nowshowindex1 - ((dataPager1._currentPageNumber - 1) * Properties.Settings.Default.PageSize);
                            dgvNew.Rows[row - 1].Selected = true;
                        }
                    }
                    else
                    {
                        dgvNew.ClearSelection();
                        if (Nowshowindex1 <= Properties.Settings.Default.PageSize)
                        {
                            dgvNew.Rows[Nowshowindex1 - 1].Selected = true;
                        }
                        else
                        {
                            int row = Nowshowindex1 - ((dataPager1._currentPageNumber - 1) * Properties.Settings.Default.PageSize);
                            dgvNew.Rows[row - 1].Selected = true;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 新下一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblToNext_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (dgvNew.SelectedRows.Count > 0)
            {
                rtbNew.Text = "";
                Nowshowindex1++;
                NextPro1();
                DataRow[] dr = Alldt1.Select("Id='" + Nowshowindex1 + "'");
                if (dr.Length > 0)
                {
                    string para = dr[0]["ParagraphText"].ToString();
                    IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
                    if (paralist.Count > 0)
                    {
                        foreach (var item in paralist)
                        {
                            if (item != "")
                            {
                                rtbNew.Text += item + "\r\n";
                            }

                        }
                        string par = dr[0]["Par"].ToString();
                        //定位
                        if (!string.IsNullOrEmpty(par))
                        {
                            PositionExtractValue(par.Remove(par.Length - 1, 1));
                        }
                        dgvNew.ClearSelection();
                        if (Nowshowindex1 <= Properties.Settings.Default.PageSize)
                        {
                            dgvNew.Rows[Nowshowindex1 - 1].Selected = true;
                        }
                        else
                        {
                            int row = Nowshowindex1 - ((dataPager1._currentPageNumber - 1) * Properties.Settings.Default.PageSize);
                            dgvNew.Rows[row - 1].Selected = true;
                        }
                    }
                    else
                    {
                        dgvNew.ClearSelection();
                        if (Nowshowindex1 <= Properties.Settings.Default.PageSize)
                        {
                            dgvNew.Rows[Nowshowindex1 - 1].Selected = true;
                        }
                        else
                        {
                            int row = Nowshowindex1 - ((dataPager1._currentPageNumber - 1) * Properties.Settings.Default.PageSize);
                            dgvNew.Rows[row - 1].Selected = true;
                        }
                    }
                }

            }
        }

        public void NextPro1()
        {
            if (dataPager1._currentPageNumber == 0)
            {
                if (Nowshowindex1 <= 0)
                {
                    lblToPre.Enabled = false;
                }
                else
                {
                    lblToPre.Enabled = true;
                }
            }
            else
            {
                if (Nowshowindex1 <= startShowIndex1)
                {
                    lblToPre.Enabled = false;
                }
                else
                {
                    lblToPre.Enabled = true;
                }
                if (Nowshowindex1 >= endShowIndex1)
                {
                    lblToNext.Enabled = false;
                }
                else
                {
                    lblToNext.Enabled = true;
                }
            }

        }

        /// <summary>
        /// 新内容数据区选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvNew_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex > 0)
            {
                isnr = true;
                index = e.RowIndex;
                rtbNew.Text = "";
                string par = string.Empty;
                string para = dgvNew.Rows[e.RowIndex].Cells["ParagraphText1"].Value.ToString();
                if (dgvNew.Rows[e.RowIndex].Cells["Par"].Value != null)
                {
                    par = dgvNew.Rows[e.RowIndex].Cells["Par"].Value.ToString();
                }
                Nowshowindex1 = Convert.ToInt32(dgvNew.Rows[e.RowIndex].Cells["id1"].Value.ToString());
                NextPro1();
                IList<string> paralist = getregex.GetParseList("CC1509101522300001", para);
                if (paralist.Count > 0)
                {
                    foreach (var item in paralist)
                    {
                        if (item != "")
                        {
                            rtbNew.Text += item + "\r\n";
                        }
                    }
                }
                //定位
                if (!string.IsNullOrEmpty(par))
                {
                    PositionExtractValue(par.Remove(par.Length - 1, 1));
                    //rtbNew.SelectionStart = 0;
                    //rtbNew.SelectionLength = rtbNew.Text.Length;
                    //rtbNew.SelectionBackColor = Color.White;
                    //var r = new System.Text.RegularExpressions.Regex(par.Trim()); //定义一个Regex对象实例
                    //var mc = r.Matches(rtbNew.Text);
                    ////符合条件个数
                    //lblKeywordCount1.Text = mc.Count.ToString();
                    ////当前第一条
                    //lblKeywordsCurrent1.Text = 1.ToString();
                    //_matchCollection1 = mc;
                    //for (int i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
                    //{
                    //    int start = mc[i].Index; //记录匹配字符的位置
                    //    int length = (par.Trim()).Length;
                    //    rtbNew.SelectionStart = start;
                    //    rtbNew.SelectionLength = length;
                    //    rtbNew.SelectionBackColor = Color.Red;
                    //}

                    ////定位到指定满足条件的第一个文字上  todo by zhangpeng
                    //var firstIndex = rtbNew.Find(par.Trim());
                    ////查询不到关键字则提示后直接退出
                    //if (firstIndex == -1)
                    //{
                    //    // MsgBox.Warn("查无此关键词");
                    //    return;
                    //}


                    //rtbNew.Focus();
                    //rtbNew.SelectionStart = firstIndex;
                    //rtbNew.ScrollToCaret();
                }
            }
        }

        private void PositionExtractValue(string contextExtractValue)
        {
            int start = 0;
            int end = this.rtbNew.Text.Length;
            int index = rtbNew.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
            int js = 0;
            if (index == -1)//不连贯的文本循环定位
            {
                string[] cfTQContext = contextExtractValue.Split('\r');
                int zjs = 0;
                for (int i = 0; i < cfTQContext.Length; i++)
                {
                    string newcontext = cfTQContext[i].ToString();
                    if (!string.IsNullOrEmpty(newcontext))
                    {
                        int startnew = 0;
                        index = rtbNew.Find(newcontext, startnew, end, RichTextBoxFinds.None);
                        while (index != -1)
                        {
                            zjs++;
                            rtbNew.SelectionFont = new System.Drawing.Font(rtbNew.SelectionFont, FontStyle.Underline | FontStyle.Bold);
                            rtbNew.SelectionColor = Color.Red;
                            if (zjs == 1)
                            {
                                rtbNew.ScrollToCaret();
                            }
                            if (zjs > 100)
                            {
                                break;
                            }
                            start = index + newcontext.Length;
                            if (start == end)
                            {
                                index = -1;
                            }
                            else
                            {
                                index = rtbNew.Find(newcontext, start, end, RichTextBoxFinds.None);
                            }
                        }
                    }
                }
            }
            while (index != -1)
            {
                //  rtbNew.SelectedText
                rtbNew.SelectionFont = new System.Drawing.Font(rtbNew.SelectionFont, FontStyle.Underline | FontStyle.Bold);
                rtbNew.SelectionColor = Color.Red;
                rtbNew.ScrollToCaret();
                start = index + contextExtractValue.Length;
                index = rtbNew.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
                js++;
                if (js > 100)
                    break;
            }
        }

        private void PositionExtractValueNew(string contextExtractValue)
        {
            int start = 0;
            int end = this.rtbNew1.Text.Length;
            int index = rtbNew1.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
            int js = 0;
            if (index == -1)//不连贯的文本循环定位
            {
                string[] cfTQContext = contextExtractValue.Split('\r');
                int zjs = 0;
                for (int i = 0; i < cfTQContext.Length; i++)
                {
                    string newcontext = cfTQContext[i].ToString();
                    if (!string.IsNullOrEmpty(newcontext))
                    {
                        int startnew = 0;
                        index = rtbNew1.Find(newcontext, startnew, end, RichTextBoxFinds.None);
                        while (index != -1)
                        {
                            zjs++;
                            rtbNew1.SelectionFont = new System.Drawing.Font(rtbNew1.SelectionFont, FontStyle.Underline | FontStyle.Bold);
                            rtbNew1.SelectionColor = Color.Red;
                            if (zjs == 1)
                            {
                                rtbNew1.ScrollToCaret();
                            }
                            if (zjs > 100)
                            {
                                break;
                            }
                            start = index + newcontext.Length;
                            if (start == end)
                            {
                                index = -1;
                            }
                            else
                            {
                                index = rtbNew1.Find(newcontext, start, end, RichTextBoxFinds.None);
                            }
                        }
                    }
                }
            }
            while (index != -1)
            {
                //  rtbNew1.SelectedText
                rtbNew1.SelectionFont = new System.Drawing.Font(rtbNew1.SelectionFont, FontStyle.Underline | FontStyle.Bold);
                rtbNew1.SelectionColor = Color.Red;
                rtbNew1.ScrollToCaret();
                start = index + contextExtractValue.Length;
                index = rtbNew1.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
                js++;
                if (js > 100)
                    break;
            }
        }

        //private void PositionExtractValueNew1(string contextExtractValue)
        //{
        //    int start = 0;
        //    int end = this.rtbNew2.Text.Length;
        //    int index = rtbNew2.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
        //    int js = 0;
        //    if (index == -1)//不连贯的文本循环定位
        //    {
        //        string[] cfTQContext = contextExtractValue.Split('\r');
        //        int zjs = 0;
        //        for (int i = 0; i < cfTQContext.Length; i++)
        //        {
        //            string newcontext = cfTQContext[i].ToString();
        //            if (!string.IsNullOrEmpty(newcontext))
        //            {
        //                int startnew = 0;
        //                index = rtbNew2.Find(newcontext, startnew, end, RichTextBoxFinds.None);
        //                while (index != -1)
        //                {
        //                    zjs++;
        //                    rtbNew2.SelectionFont = new System.Drawing.Font(rtbNew2.SelectionFont, FontStyle.Underline | FontStyle.Bold);
        //                    rtbNew2.SelectionColor = Color.Red;
        //                    if (zjs == 1)
        //                    {
        //                        rtbNew2.ScrollToCaret();
        //                    }
        //                    if (zjs > 100)
        //                    {
        //                        break;
        //                    }
        //                    start = index + newcontext.Length;
        //                    if (start == end)
        //                    {
        //                        index = -1;
        //                    }
        //                    else
        //                    {
        //                        index = rtbNew2.Find(newcontext, start, end, RichTextBoxFinds.None);
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    while (index != -1)
        //    {
        //        //  rtbNew2.SelectedText
        //        rtbNew2.SelectionFont = new System.Drawing.Font(rtbNew2.SelectionFont, FontStyle.Underline | FontStyle.Bold);
        //        rtbNew2.SelectionColor = Color.Red;
        //        rtbNew2.ScrollToCaret();
        //        start = index + contextExtractValue.Length;
        //        index = rtbNew2.Find(contextExtractValue, start, end, RichTextBoxFinds.None);
        //        js++;
        //        if (js > 100)
        //            break;
        //    }
        //}


        #region 定位
        /// <summary>
        /// 定位开始索引
        /// </summary>
        private int locationIndex1 = 0;

        /// <summary>
        /// 匹配关键字的集合
        /// </summary>
        private MatchCollection _matchCollection1;

        /// <summary>
        /// 定位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(txbKey.Text.Trim())) return;

            rtbNew.SelectionStart = 0;
            rtbNew.SelectionLength = rtbNew.Text.Length;
            rtbNew.SelectionBackColor = Color.White;
            var r = new System.Text.RegularExpressions.Regex(txbKey.Text.Trim()); //定义一个Regex对象实例
            var mc = r.Matches(rtbNew.Text);
            //符合条件个数
            lblKeywordCount1.Text = mc.Count.ToString();
            //当前第一条
            lblKeywordsCurrent1.Text = 1.ToString();
            _matchCollection1 = mc;
            for (int i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
            {
                int start = mc[i].Index; //记录匹配字符的位置
                int length = (txbKey.Text.Trim()).Length;
                rtbNew.SelectionStart = start;
                rtbNew.SelectionLength = length;
                rtbNew.SelectionBackColor = Color.Red;
            }

            //定位到指定满足条件的第一个文字上  todo by zhangpeng
            var firstIndex = rtbNew.Find(txbKey.Text.Trim());
            //查询不到关键字则提示后直接退出
            if (firstIndex == -1)
            {
                MsgBox.Warn("查无此关键词");
                return;
            }


            rtbNew.Focus();
            rtbNew.SelectionStart = firstIndex;
            rtbNew.ScrollToCaret();
        }

        /// <summary>
        /// 上一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(txbKey.Text))
            {
                MsgBox.Warn("请输入关键词!");
                return;
            }
            if (_matchCollection1 == null || _matchCollection1.Count == 0)
            {
                MsgBox.Warn("请先定位!");
                return;
            }
            if (0 <= (locationIndex1 - 1))
            {
                locationIndex1--;
                int start = _matchCollection1[locationIndex1].Index;
                int length = (txbKey.Text.Trim()).Length;
                rtbNew.SelectionStart = start;
                rtbNew.SelectionLength = length;
                rtbNew.Focus();
                rtbNew.ScrollToCaret();
                //当前第几条
                lblKeywordsCurrent1.Text = (locationIndex1 + 1).ToString();

            }
            else
            {
                MsgBox.Warn("已经是第一个");
                return;
            }
        }

        /// <summary>
        /// 下一条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (string.IsNullOrEmpty(txbKey.Text))
            {
                MsgBox.Warn("请输入关键词!");
                return;
            }
            if (_matchCollection1 == null || _matchCollection1.Count == 0)
            {
                MsgBox.Warn("请先定位!");
                return;
            }

            if (_matchCollection1.Count > (locationIndex1 + 1))
            {
                locationIndex1++;
                int start = _matchCollection1[locationIndex1].Index;
                int length = (txbKey.Text.Trim()).Length;
                rtbNew.SelectionStart = start;
                rtbNew.SelectionLength = length;
                rtbNew.Focus();
                rtbNew.ScrollToCaret();
                //当前第几条
                lblKeywordsCurrent1.Text = (locationIndex1 + 1).ToString();
            }
            else
            {
                MsgBox.Warn("已经是最后一个");
                return;
            }
        }
        #endregion

        bool isnr = false;
        //鼠标按下的行数
        private int PressRow = 0;

        private void dgvNew_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1 && isnr == false)
            {
                int start = PressRow;
                int end = e.RowIndex;
                if (start <= end)//正选
                {
                    for (int a = start; a <= end; a++)
                    {
                        if ((Convert.ToBoolean(dgvNew.Rows[a].Cells[0].Value) == false))
                        {
                            dgvNew.Rows[a].Cells[0].Value = "True";
                        }
                        else if ((Convert.ToBoolean(dgvNew.Rows[a].Cells[0].Value) == true))
                        {
                            dgvNew.Rows[a].Cells[0].Value = "False";
                        }
                        else
                            continue;
                    }
                    // Allchecknum();//统计选中数量方法
                }
                else//反选
                {
                    for (int a = end; a <= start; a++)
                    {
                        if ((Convert.ToBoolean(dgvNew.Rows[a].Cells[0].Value) == false))
                        {
                            dgvNew.Rows[a].Cells[0].Value = "True";
                        }
                        else if ((Convert.ToBoolean(dgvNew.Rows[a].Cells[0].Value) == true))
                        {
                            dgvNew.Rows[a].Cells[0].Value = "False";
                        }
                        else
                            continue;
                    }
                    //Allchecknum();//统计选中数量方法
                }
            }
            isnr = false;
        }

        private void dgvNew_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    dgvNew.ClearSelection();
                    dgvNew.Rows[e.RowIndex].Selected = true;
                    dgvNew.CurrentCell = dgvNew.Rows[e.RowIndex].Cells[e.ColumnIndex];
                }
            }
            else
            {
                if (e.ColumnIndex == 0 && e.RowIndex != -1)
                {
                    PressRow = e.RowIndex;
                }
            }
        }

        private void dataPager2_PageNumberChanging(object sender, Controls.DataPagerPageIndexChangingEventArgs e)
        {
            //当前页
            var page = dataPager2._currentPageNumber;
            //每页显示条数
            var pageSize = e.MaximumRows;
            var startRowIndex = e.StartRowIndex;
            startShowIndex1 = startRowIndex + 1;
            var maximumRows = e.MaximumRows;
            var endRowIndex = e.StartRowIndex + e.MaximumRows;
            endShowIndex1 = endRowIndex;
            #region 查询条件
            //lbelCount.Text = "";
            IList<DataRow> dtRows = PaginationDataSource<DataRow>(dtsysArgument.Select(), page, pageSize, dtsysArgument.Rows.Count);
            #endregion

            if (dtRows.Count > 0)
            {
                e.TotalCount = dtsysArgument.Rows.Count;
                dgvNew2.DataSource = Alldt1 = dtRows.CopyToDataTable<DataRow>();
            }
            else
            {
                e.TotalCount = 0;
                dgvNew2.DataSource = new DataTable();
            }
            dgvNew2.ClearSelection();
            rtbNew1.Text = "";
        }

        private void dgvNew2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex == 0)
            {
                lbltitleText.Text = "";
            }
            if (e.RowIndex >= 0 && e.ColumnIndex == 3)
            {
                rtbNew1.Text = "";

                string caseId = dgvNew2.Rows[e.RowIndex].Cells["CaseIdd"].Value.ToString();
                string content = dgvNew2.Rows[e.RowIndex].Cells["ATR_Content"].Value.ToString();
                if (!string.IsNullOrEmpty(caseId))
                {
                    string res1 = caseLogicbll.GetCaseLogicPartInfoesNew(caseId);
                    if (!string.IsNullOrEmpty(res1))
                    {
                        rtbNew1.Text = res1;
                    }

                    string res = caseLogicbll.GetCaseLogicPartInfoes(caseId);
                    if (!string.IsNullOrEmpty(res1)&&!string.IsNullOrEmpty(res))
                    {
                        rtbNew1.Text += "\r\n";
                        rtbNew1.Text += res;
                    }
                    else if (string.IsNullOrEmpty(res1) && !string.IsNullOrEmpty(res))
                    {
                        rtbNew1.Text += res;
                    }
                }
                //定位
                if (!string.IsNullOrEmpty(content))
                {
                    PositionExtractValueNew(content);
                   // PositionExtractValueNew1(content);
                }
                if (argumentdt != null && argumentdt.Rows.Count > 0)
                {
                    tvNode1.CollapseAll();
                    if (argumentdt.Select(" CaseId='" + caseId + "' and ATR_Content='" + content + "' and ATR_TypeID<>''  ").Length > 0)
                    {
                        DataTable dt = argumentdt.Select(" CaseId='" + caseId + "' and ATR_Content='" + content + "'  and ATR_TypeID<>''  ").CopyToDataTable();
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            lbltitleText.Text = dt.Rows.Count.ToString();
                            foreach (DataRow item in dt.Rows)
                            {
                                string ccid = item["ATR_TypeID"].ToString();
                                QueryNode_Page(ccid);
                            }
                        }
                    }
                    else
                    {
                        lbltitleText.Text = "0";
                    }
                }

            }
        }

        /// <summary>
        /// 定位到目标节点
        /// </summary>
        /// <param name="dt">查询返回结果集</param>
        /// <param name="showindex">第几条</param>
        private void QueryNode_Page(string ccid)
        {
            if (caseTreeNodeRode.Rows.Count > 0)
            {
                if (caseTreeNodeRode.Select(" cc_id='" + ccid + "' ").Length > 0)
                {
                    DataRow dr = caseTreeNodeRode.Select(" cc_id='" + ccid + "' ")[0];
                    string allParentId = dr["AllParentId"].ToString();
                    var NotePidArr = allParentId.Split(',');//所有父级
                    for (var i = 0; i < NotePidArr.Length; i++)
                    {
                        if (i != NotePidArr.Length - 1)
                        {
                            var Node = FindNode(NotePidArr[i]);
                            if (Node != null)
                            {
                                Node.Expand();//拖出所有父级节点
                            }
                        }
                        else  //最后一级节点为查找节点
                        {
                            // tVCaseCause.ExpandAll();
                            TreeNode node = FindNode(NotePidArr[i]);
                            node.ForeColor = Color.Blue;
                            // tvNode1.SelectedNode = node;//定位          
                        }
                    }
                }

            }
        }

        /// <summary>
        /// 查找节点
        /// </summary>
        /// <param name="Nodeid"></param>
        /// <returns></returns>
        private TreeNode FindNode(string Nodeid)
        {
            foreach (var node in NodeList)//遍历现在界面上的所有节点
            {
                if (node.Tag.ToString() == Nodeid)
                {
                    return node;
                }
            }
            return null;
            //return (TreeNode)NodeList[Nodeid];
        }

        /// <summary>
        /// 全部展开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            clicknodeNew?.ExpandAll();
        }

        /// <summary>
        /// 删除子节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认要删除节点" + clicknodeNew.Text + "及其子节点吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    if (caseCauseBll.DeleteSYS_CaseCause(clicknodeNew.Tag.ToString(), clicknodeNew.Text, Gvar.uo.m_displayName))
                    {
                        MessageBox.Show("删除成功!");
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节点
                        clicknodeNew.Parent.Nodes.Remove(clicknodeNew);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("删除失败!" + ex.Message);
                }
            }
        }

        /// <summary>
        /// 添加同级节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            if (this.dgvNew2.CurrentCell != null&& this.dgvNew2.CurrentCell.Value != null)
            {               
                    str = this.dgvNew2.CurrentCell.Value.ToString();
                    AddCaseNode addNode = new AddCaseNode("添加同级节点", str, clicknodeNew.Parent.Text, clicknodeNew.Parent.FullPath, clicknodeNew.Parent.Tag.ToString()); ;
                    var dialogResult = addNode.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                        clicknodeNew.Parent.Collapse();
                        clicknodeNew.Parent.Expand();
                        // LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                    }               
            }
            else
            {
                AddCaseNode addNode = new AddCaseNode("添加同级节点", "", clicknodeNew.Text, clicknodeNew.FullPath, clicknodeNew.Tag.ToString());
                var dialogResult = addNode.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                    clicknodeNew.Parent.Collapse();
                    clicknodeNew.Parent.Expand();
                    //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                }
            }

        }

        /// <summary>
        /// 添加子节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            if (this.dgvNew2.CurrentCell != null)
            {
                if (this.dgvNew2.CurrentCell.Value != null)
                {
                    str = this.dgvNew2.CurrentCell.Value.ToString();
                    AddCaseNode addNode = new AddCaseNode("添加子节点", str, clicknodeNew.Text, clicknodeNew.FullPath, clicknodeNew.Tag.ToString());
                    var dialogResult = addNode.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                        clicknodeNew.Collapse();
                        clicknodeNew.Expand();
                        //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                    }
                }
                else
                {
                    AddCaseNode addNode = new AddCaseNode("添加子节点", "", clicknodeNew.Text, clicknodeNew.FullPath, clicknodeNew.Tag.ToString());
                    var dialogResult = addNode.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                        clicknodeNew.Collapse();
                        clicknodeNew.Expand();
                        //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                    }
                }
            }
            else
            {
                AddCaseNode addNode = new AddCaseNode("添加子节点", "", clicknodeNew.Text, clicknodeNew.FullPath, clicknodeNew.Tag.ToString());
                var dialogResult = addNode.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                    clicknodeNew.Collapse();
                    clicknodeNew.Expand();
                    //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                }
            }
           
        }

        /// <summary>
        /// 添加来源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 添加来源ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (editnodeNew != null)
            {
                try
                {
                    FrmSourceDefaultSetting fs = new FrmSourceDefaultSetting(1);
                    fs.ClickNode = editnodeNew;
                    var dialogResult = fs.ShowDialog();
                }
                catch (Exception ex)
                {
                    throw new Exception("添加失败：" + ex.Message);
                }
                #region 旧代码
                //if (MessageBox.Show("确认给该节点一键添加来源数据吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //{
                //    string msg_exist = string.Empty;
                //    var iSuccess = 0;
                //    var iFail = 0;

                //    //添加来源表
                //    DataTable sysExpressSourceTable = new DataTable();
                //    sysExpressSourceTable.Columns.Add("ES_ID", typeof(string));
                //    sysExpressSourceTable.Columns.Add("CC_ID", typeof(string));
                //    sysExpressSourceTable.Columns.Add("Source_ID", typeof(string));
                //    sysExpressSourceTable.Columns.Add("Source_ParagraphID", typeof(string));
                //    sysExpressSourceTable.Columns.Add("Source_Name", typeof(string));
                //    sysExpressSourceTable.Columns.Add("Source_ParagraphName", typeof(string));
                //    sysExpressSourceTable.Columns.Add("CC_RegexInfoCode", typeof(string));
                //    sysExpressSourceTable.Columns.Add("ES_Purpose", typeof(string));
                //    sysExpressSourceTable.Columns.Add("Source_TextType", typeof(string));

                //    sysExpressSourceTable.Clear();
                //    NewIDBLL newid = new NewIDBLL();
                //    AboutRegexBLL regexbll = new AboutRegexBLL();
                //    Reg_InfoUnit nodeChild = new Reg_InfoUnit();
                //    Express_SourceBLL SourceBLL = new Express_SourceBLL();

                //    string codeType = editnodeNew.Name;
                //    //16 争议焦点
                //    //17 裁判理由
                //    //22 裁判结果
                //    if (codeType == "16")
                //    {
                //        string ccRegexInfoCode = string.Empty;
                //        DataRow drr = sysExpressSourceTable.NewRow();
                //        drr["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr["Source_ID"] = "MSCourtRecord";
                //        drr["Source_ParagraphID"] = "MS_CR_ArgumentFocus";
                //        drr["Source_Name"] = "民事法庭笔录";
                //        drr["Source_ParagraphName"] = "争议焦点原文";
                //        drr["ES_Purpose"] = "70af0cc4-c9b2-436d-9ad9-9b0cd6685ef3";
                //        drr["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr);

                //        DataRow drr1 = sysExpressSourceTable.NewRow();
                //        drr1["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr1["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr1["Source_ID"] = "MSCourtRecord";
                //        drr1["Source_ParagraphID"] = "MS_CR_DefendantSuggest";
                //        drr1["Source_Name"] = "民事法庭笔录";
                //        drr1["Source_ParagraphName"] = "被告答辩";
                //        drr1["ES_Purpose"] = "be907163-377d-4e62-830c-d02de6895d88";
                //        drr1["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr1["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr1);

                //        DataRow drr2 = sysExpressSourceTable.NewRow();
                //        drr2["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr2["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr2["Source_ID"] = "RecordProduction";
                //        drr2["Source_ParagraphID"] = "AnswerOpinion";
                //        drr2["Source_Name"] = "笔录制作";
                //        drr2["Source_ParagraphName"] = "答辩意见";
                //        drr2["ES_Purpose"] = "be907163-377d-4e62-830c-d02de6895d88";
                //        drr2["Source_TextType"] = "1";
                //        drr2["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr2);

                //        DataRow drr3 = sysExpressSourceTable.NewRow();
                //        drr3["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr3["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr3["Source_ID"] = "JudgeBook";
                //        drr3["Source_ParagraphID"] = "CourtAffirm";
                //        drr3["Source_Name"] = "判决书";
                //        drr3["Source_ParagraphName"] = "裁判理由";
                //        drr3["ES_Purpose"] = "c32c4642-4a35-4b34-991b-c096403609ee";
                //        drr3["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr3["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr3);

                //        DataRow drr4 = sysExpressSourceTable.NewRow();
                //        drr4["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr4["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr4["Source_ID"] = "MSSuitBook";
                //        drr4["Source_ParagraphID"] = "MS_IM_Litigation Request";
                //        drr4["Source_Name"] = "起诉状";
                //        drr4["Source_ParagraphName"] = "诉讼请求";
                //        drr4["ES_Purpose"] = "be907163-377d-4e62-830c-d02de6895d88";
                //        drr4["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr4["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr4);
                //    }
                //    else if (codeType == "17")
                //    {
                //        string ccRegexInfoCode = string.Empty;
                //        DataRow drr = sysExpressSourceTable.NewRow();
                //        drr["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr["Source_ID"] = "MSCourtRecord";
                //        drr["Source_ParagraphID"] = "MS_CR_SuitEvid";
                //        drr["Source_Name"] = "民事法庭笔录";
                //        drr["Source_ParagraphName"] = "原告举证内容";
                //        drr["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr);

                //        DataRow drr1 = sysExpressSourceTable.NewRow();
                //        drr1["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr1["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr1["Source_ID"] = "MSCourtRecord";
                //        drr1["Source_ParagraphID"] = "MS_CR_PlaintiffCross-examination";
                //        drr1["Source_Name"] = "民事法庭笔录";
                //        drr1["Source_ParagraphName"] = "原告质证";
                //        drr1["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr1["Source_TextType"] = "1";
                //        drr1["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr1);

                //        DataRow drr2 = sysExpressSourceTable.NewRow();
                //        drr2["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr2["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr2["Source_ID"] = "MSCourtRecord";
                //        drr2["Source_ParagraphID"] = "MS_CR_PlaintiffArgueSuggest";
                //        drr2["Source_Name"] = "民事法庭笔录";
                //        drr2["Source_ParagraphName"] = "原告辩论意见";
                //        drr2["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr2["Source_TextType"] = "1";
                //        drr2["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr2);

                //        DataRow drr3 = sysExpressSourceTable.NewRow();
                //        drr3["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr3["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr3["Source_ID"] = "JudgeBook";
                //        drr3["Source_ParagraphID"] = "CourtAffirm";
                //        drr3["Source_Name"] = "判决书";
                //        drr3["Source_ParagraphName"] = "裁判理由";
                //        drr3["ES_Purpose"] = "c32c4642-4a35-4b34-991b-c096403609ee";
                //        drr3["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr3["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr3);

                //        //被告
                //        DataRow drr4 = sysExpressSourceTable.NewRow();
                //        drr4["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr4["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr4["Source_ID"] = "MSCourtRecord";
                //        drr4["Source_ParagraphID"] = "MS_CR_DefendantOpinion";
                //        drr4["Source_Name"] = "民事法庭笔录";
                //        drr4["Source_ParagraphName"] = "被告质证";
                //        drr4["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr4["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr4["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr4);

                //        DataRow drr5 = sysExpressSourceTable.NewRow();
                //        drr5["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr5["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr5["Source_ID"] = "MSCourtRecord";
                //        drr5["Source_ParagraphID"] = "MS_CR_AnswerEvidence";
                //        drr5["Source_Name"] = "民事法庭笔录";
                //        drr5["Source_ParagraphName"] = "被告举证内容";
                //        drr5["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr5["Source_TextType"] = "1";
                //        drr5["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr5);

                //        DataRow drr6 = sysExpressSourceTable.NewRow();
                //        drr6["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr6["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr6["Source_ID"] = "MSCourtRecord";
                //        drr6["Source_ParagraphID"] = "MS_CR_DefendantArgueSuggest";
                //        drr6["Source_Name"] = "民事法庭笔录";
                //        drr6["Source_ParagraphName"] = "被告辩论意见";
                //        drr6["ES_Purpose"] = "b4ea9faf-e04c-4b4a-8d98-3fc5f7a72d76";
                //        drr6["Source_TextType"] = "1";
                //        drr6["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr6);

                //        DataRow drr7 = sysExpressSourceTable.NewRow();
                //        drr7["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr7["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr7["Source_ID"] = "JudgeBook";
                //        drr7["Source_ParagraphID"] = "CourtAffirm";
                //        drr7["Source_Name"] = "判决书";
                //        drr7["Source_ParagraphName"] = "裁判理由";
                //        drr7["ES_Purpose"] = "c32c4642-4a35-4b34-991b-c096403609ee";
                //        drr7["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr7["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr7);
                //    }
                //    else if (codeType == "22")
                //    {
                //        string ccRegexInfoCode = string.Empty;
                //        DataRow drr = sysExpressSourceTable.NewRow();
                //        drr["ES_ID"] = newid.JudgeDoc_CreateID("SYS_Express_Source");
                //        drr["CC_ID"] = editnodeNew.Tag.ToString();
                //        drr["Source_ID"] = "udgeBook";
                //        drr["Source_ParagraphID"] = "CourtAffirm";
                //        drr["Source_Name"] = "判决书";
                //        drr["Source_ParagraphName"] = "裁判理由";
                //        drr["ES_Purpose"] = "c32c4642-4a35-4b34-991b-c096403609ee";
                //        drr["Source_TextType"] = "1";
                //        #region  信息单元
                //        nodeChild.EI_Name = editnodeNew.Text;
                //        nodeChild.EN_ID = "EI_ID1507221438500001";
                //        nodeChild.EI_Remark = "";
                //        nodeChild.EI_ID = newid.CreateID("Reg_InfoUnit");
                //        nodeChild.EI_Code = nodeChild.EI_ID;//编号==ID 
                //        regexbll.AddReg_InfoUnit(nodeChild);
                //        ccRegexInfoCode = nodeChild.EI_Code;
                //        #endregion
                //        drr["CC_RegexInfoCode"] = ccRegexInfoCode;
                //        sysExpressSourceTable.Rows.Add(drr);
                //    }

                //    if (sysExpressSourceTable != null && sysExpressSourceTable.Rows.Count > 0)
                //    {
                //        for (int i = 0; i < sysExpressSourceTable.Rows.Count; i++)
                //        {
                //            SysExpressSource model = new SysExpressSource
                //            {
                //                ES_ID = sysExpressSourceTable.Rows[i]["ES_ID"].ToString(),
                //                CC_ID = sysExpressSourceTable.Rows[i]["CC_ID"].ToString(),
                //                Source_ID = sysExpressSourceTable.Rows[i]["Source_ID"].ToString(),
                //                Source_Name = sysExpressSourceTable.Rows[i]["Source_Name"].ToString(),
                //                Source_ParagraphID = sysExpressSourceTable.Rows[i]["Source_ParagraphID"].ToString(),
                //                Source_ParagraphName = sysExpressSourceTable.Rows[i]["Source_ParagraphName"].ToString(),
                //                EsPurposeId = sysExpressSourceTable.Rows[i]["ES_Purpose"].ToString(),
                //                Source_TextType = sysExpressSourceTable.Rows[i]["Source_TextType"].ToString(),
                //                CC_RegexInfoCode = sysExpressSourceTable.Rows[i]["CC_RegexInfoCode"].ToString(),
                //            };
                //            if (!SourceBLL.Exists(model.CC_ID, model.Source_ID, model.Source_ParagraphID, model.Source_TextType, model.EsPurposeId))
                //            {
                //                if (SourceBLL.AddSource(model))
                //                {
                //                    iSuccess++;
                //                }
                //                else
                //                {
                //                    iFail++;
                //                }

                //            }
                //            else
                //            {
                //                //msg_exist += string.Format("{0},用途为{1}的规则已存在\r\n", model.Source_Name + "-" + model.Source_ParagraphName, model.EsPurposeName);
                //                //iFail++;
                //            }
                //        }
                //        MsgBox.OK(string.Format("添加成功{0}条。\r\n失败{1}条。\r\n{2}", iSuccess, iFail, msg_exist.TrimEnd(',')));
                //    }
                //}

                #endregion            }
            }
        }

        /// <summary>
        /// 规则管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 规则管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Analysis al = new Analysis(editnodeNew.Tag.ToString());
            al.Show();
            // editnodeNew
        }

        /// <summary>
        /// 修改争议焦点选中状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvNew2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.RowIndex >= 0 && e.ColumnIndex == 4)
            //{
            //    string caseId = dgvNew2.Rows[e.RowIndex].Cells["CaseIdd"].Value.ToString();
            //    string content = dgvNew2.Rows[e.RowIndex].Cells["ATR_Content"].Value.ToString();
            //    var check = (DataGridViewCheckBoxCell)dgvNew2.Rows[e.RowIndex].Cells["checkType"];
            //    if (check.Value != DBNull.Value && Convert.ToBoolean(check.Value))
            //    {
            //        sysArgumentBll.UpdateArgumentState(1, caseId, content);
            //    }
            //    else
            //    {
            //        sysArgumentBll.UpdateArgumentState(0, caseId, content);
            //    }
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int num = 0;
            for (var i = 0; i <= dgvNew2.Rows.Count - 1; i++)
            {
                var check = (DataGridViewCheckBoxCell)dgvNew2.Rows[i].Cells["CheckRow1"];
                if (check.Value != DBNull.Value && Convert.ToBoolean(check.Value))
                {
                    num++;
                }
            }
            if (num == 0)
            {
                MsgBox.Warn("请勾选需要提交的数据后再试");
                return;
            }
            else
            {
                for (var i = 0; i <= dgvNew2.Rows.Count - 1; i++)
                {
                    string caseId = dgvNew2.Rows[i].Cells["CaseIdd"].Value.ToString();
                    string content = dgvNew2.Rows[i].Cells["ATR_Content"].Value.ToString();
                    var check = (DataGridViewCheckBoxCell)dgvNew2.Rows[i].Cells["CheckRow1"];
                    var check1 = (DataGridViewCheckBoxCell)dgvNew2.Rows[i].Cells["checkType"];

                    if (check.Value != DBNull.Value && check1.Value != DBNull.Value && Convert.ToBoolean(check.Value) && check1.Value.ToString() == "1")
                    {
                        sysArgumentBll.UpdateArgumentState(1, caseId, content);
                    }
                    else if (check.Value != DBNull.Value && check1.Value == DBNull.Value && Convert.ToBoolean(check.Value) && string.IsNullOrEmpty(check1.Value.ToString()))
                    {
                        sysArgumentBll.UpdateArgumentState(0, caseId, content);
                    }
                }
                MessageBox.Show("提交成功！");
                lblNo.Text = sysArgumentBll.GetSysArgumentCount(t_Case_HeadWords.Text.Trim()).ToString();
                dtsysArgument = sysArgumentBll.GetSysArgumentTextRelData(t_Case_HeadWords.Text.Trim());
                if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                {
                    for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                    {
                        dtsysArgument.Rows[i]["id"] = i + 1;
                    }
                    dataPager2.ChangePageNumber(1);
                }
                else
                {
                    if (dtsysArgument != null)
                    {
                        dtsysArgument.Clear();
                    }
                    dataPager2.ChangePageNumber(1);
                    MessageBox.Show("没有获取到数据！");
                }
            }
        }

        /// <summary>
        /// 重新分析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAnalysis_Click(object sender, EventArgs e)
        {
            int num = 0;
            for (var i = 0; i <= dgvNew2.Rows.Count - 1; i++)
            {
                var check = (DataGridViewCheckBoxCell)dgvNew2.Rows[i].Cells["CheckRow1"];
                if (check.Value != DBNull.Value && Convert.ToBoolean(check.Value))
                {
                    num++;
                }
            }
            if (num == 0)
            {
                MsgBox.Warn("请勾选需要提交的数据后再试");
                return;
            }
            else
            {
                AnalysisArgumentFocus.AnalysisMain analysisMain = new AnalysisArgumentFocus.AnalysisMain();
                AnalysisArgumentFocus.AnalysisMain.CommonConnection = "Data Source=192.168.1.52;Initial Catalog=LdtCommonManage;User ID=sa;Password=ldtlaw_123";
                AnalysisArgumentFocus.AnalysisMain.SystemConnection = "Data Source=192.168.1.52;Initial Catalog=Ldt_JudgeDocSystem;User ID=sa;Password=ldtlaw_123";

                for (var i = 0; i <= dgvNew2.Rows.Count - 1; i++)
                {
                    string caseId = dgvNew2.Rows[i].Cells["CaseIdd"].Value.ToString();
                    string content = dgvNew2.Rows[i].Cells["ATR_Content"].Value.ToString();
                    var check = (DataGridViewCheckBoxCell)dgvNew2.Rows[i].Cells["CheckRow1"];

                    if (check.Value != DBNull.Value && Convert.ToBoolean(check.Value))
                    {
                        if (sysArgumentBll.DelSYS_ArgumentTextRel(caseId, content))
                        {
                            string message = "";
                            string causeID = t_Case_HeadWords.Text.Trim();
                            Dictionary<string, string> listvalue = analysisMain.GetArgumentFocus(content, causeID, "MSCourtRecord", "MS_CR_ArgumentFocus", out message);
                            if (message.Contains("成功"))
                            {
                                if (listvalue.Count > 0)
                                {
                                    foreach (var item in listvalue.Keys)
                                    {
                                        SYS_ArgumentTextRel model = new SYS_ArgumentTextRel();
                                        model.ATR_Content = content;
                                        model.CaseId = caseId;
                                        model.ATR_ID = Guid.NewGuid().ToString();
                                        model.ATR_TypeID = item.ToString();
                                        model.CauseId = causeID;
                                        sysArgumentBll.AddSYS_ArgumentTextRel(model);
                                    }
                                }
                                else
                                {
                                    SYS_ArgumentTextRel model = new SYS_ArgumentTextRel();
                                    model.ATR_Content = content;
                                    model.CaseId = caseId;
                                    model.ATR_ID = Guid.NewGuid().ToString();
                                    model.CauseId = causeID;
                                    sysArgumentBll.AddSYS_ArgumentTextRel(model);
                                }
                            }
                        }
                    }
                }
                MessageBox.Show("重新分析成功！");
                dtsysArgument = sysArgumentBll.GetSysArgumentTextRelData(t_Case_HeadWords.Text.Trim());
                if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                {
                    for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                    {
                        dtsysArgument.Rows[i]["id"] = i + 1;
                    }
                    dataPager2.ChangePageNumber(1);
                }
                else
                {
                    if (dtsysArgument != null)
                    {
                        dtsysArgument.Clear();
                    }
                    dataPager2.ChangePageNumber(1);
                    MessageBox.Show("没有获取到数据！");
                }
                LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());

            }

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txbSearch.Text.Trim()))
            {
                if (dtsysArgument.Select(" CaseId='" + txbSearch.Text.Trim() + "' or ATR_Content like '%" + txbSearch.Text.Trim() + "%' ").Length > 0)
                {
                    dtsysArgument = dtsysArgument.Select(" CaseId='" + txbSearch.Text.Trim() + "' or ATR_Content like '%" + txbSearch.Text.Trim() + "%' ").CopyToDataTable();
                    if (dtsysArgument != null && dtsysArgument.Rows.Count > 0)
                    {
                        for (int i = 0; i < dtsysArgument.Rows.Count; i++)
                        {
                            dtsysArgument.Rows[i]["id"] = i + 1;
                        }
                        dataPager2.ChangePageNumber(1);
                    }
                    else
                    {
                        if (dtsysArgument != null)
                        {
                            dtsysArgument.Clear();
                        }
                        dataPager2.ChangePageNumber(1);
                        MessageBox.Show("没有获取到数据！");
                    }
                }
            }
        }

        private void 添加同级节点ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            if (this.dgvNew2.CurrentCell != null)
            {
                if (this.dgvNew2.CurrentCell.Value != null)
                {
                    str = this.dgvNew2.CurrentCell.Value.ToString();
                    AddCaseNode addNode = new AddCaseNode("添加同级节点", str, clicknodeNew.Parent.Text, clicknodeNew.Parent.FullPath, clicknodeNew.Parent.Tag.ToString());
                    var dialogResult = addNode.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                        clicknodeNew.Parent.Collapse();
                        clicknodeNew.Parent.Expand();
                        //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                    }
                }
                else
                {
                    AddCaseNode addNode = new AddCaseNode("添加同级节点", "", clicknodeNew.Parent.Text, clicknodeNew.Parent.FullPath, clicknodeNew.Parent.Tag.ToString());
                    var dialogResult = addNode.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                        clicknodeNew.Parent.Collapse();
                        clicknodeNew.Parent.Expand();
                        //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                    }
                }
            }
            else
            {
                AddCaseNode addNode = new AddCaseNode("添加同级节点", "", clicknodeNew.Parent.Text, clicknodeNew.Parent.FullPath, clicknodeNew.Parent.Tag.ToString());
                var dialogResult = addNode.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    caseTreeNodeRode = trbll.AllGetCaseCauseByCCID(t_Case_HeadWords.Text.Trim());//父级ID的下级节                                                                                             
                    clicknodeNew.Parent.Collapse();
                    clicknodeNew.Parent.Expand();
                    //LoadCaseCauseTreeNew(t_Case_HeadWords.Text.Trim());
                }
            }
        }
    }
}
